ROBLOX获取点击砖块的玩家的名字

时间:2015-07-27 14:39:08

标签: lua roblox

我将这个脚本放在一块砖中:

local giver = 1

function onClicked()
    game.Players.[I NEED THE PLAYER NAME HERE].leaderstats.Clicks.Value = game.Players.[I NEED THE PLAYER NAME HERE].leaderstats.Clicks.Value + giver
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

现在,我需要以某种方式获取播放器的名称,点击它并将其放在我需要的位置。

2 个答案:

答案 0 :(得分:1)

The ClickDetectors's MouseClick event have the "Clicking Player" as parameter, so you can do it like this:

local giver = 1

function onClicked(Player)
    Player.leaderstats.Clicks.Value = Player.leaderstats.Clicks.Value + giver
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

However, this requires the FilteringEnabled to be set to false (not recomended).

To solve this, make a LocalScript in the brick with the code:

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    game.ReplicatedStorage:WaitForChild("BrickClick"):InvokeServer(script.Parent)
end)

And in a Script placed in the ServerScriptService put:

local Listener = game.ReplicatedStorage:FindFirstChild("BrickClick")
if Listener == nil then
    Listener = Instance.new("RemoteFunction")
    Listener.Name = "BrickClick"
    Listener.Parent = game.ReplicatedStorage
end

function Listener.OnServerInvoke(Player,Brick)
    Player.leaderstats.Clicks.Value = Player.leaderstats.Clicks.Value + 1
end

I won't point you to the wiki page for further reading, even thought it contains a bit of what you need, it contains too little information.

The ClickDetector's MouseClick info, the guide about FilteringEnabled and the guide about RemoteFunctions are better.

答案 1 :(得分:1)

尝试一下!

script.Parent.MouseClick:Connect(function(Player)
-- Kill The Player
-- The parameter is referring to game.Players So if you want to do a kill button use .Character
Player.Character:BreakJoints()

-- Change The Color To Red (Other details)
    script.Parent.Parent.BrickColor = BrickColor.new("Really red")
    script.Parent.MaxActivationDistance = 0

-- Wait 4 Secs
wait(5)

-- Change The Color To Green
script.Parent.Parent.BrickColor = BrickColor.new("Lime green")
script.Parent.MaxActivationDistance = 50
end)