Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I target the player who pressed the button in a server script?

Asked by 7 years ago

I've got a server script which is supposed to check for a players team. Server scripts do not recognise LocalPlayer as a variable, so I was wondering, what do I do?

function ColorChange()
if game.Players.LocalPlayer.Team.TeamColor == BrickColor.new("Dusty Rose")
    then
print("Dusty Rose")
            elseif game.Players.LocalPlayer.Team.TeamColor == BrickColor.new("Sand blue") 
        or
            game.Players.LocalPlayer.Team.TeamColor == BrickColor.new("Steel blue")
        then
print("Sand blue or Steel blue")
end
end

script.Parent.ClickDetector.MouseClick:connect(ColorChange)
0
"MouseClick" has a parameter of the Player. FiredDusk 1466 — 7y

1 answer

Log in to vote
1
Answered by
FiredDusk 1466 Moderation Voter
7 years ago

I left some comments below, please read.

script.Parent.ClickDetector.MouseClick:Connect(function(Player) --MouseClick takes a parameter of the Player.
    if Player.Team.TeamColor == BrickColor.new("Dusty Rose") then -- You can't get the LocalPlayer in a server script.
        print("Dusty Rose")
    elseif Player.Team.TeamColor == BrickColor.new("Sand blue") or Player.Team.TeamColor == BrickColor.new("Steel blue") then
        print("Sand blue or Steel blue")
    end
end)

If this helped, please accept :)

Ad

Answer this question