Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

"MouseClick" has a parameter of the Player.

1 answer

✓ Accepted answer

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 :)

This discussion is preserved as it was. New answers, comments, and votes are closed.