The script is:
script.Parent.Touched:connect(function(hit) green = game.Teams.Green purple = game.Teams.Purple if game.Players.LocalPlayer.Team == green then script.Parent.BrickColor = BrickColor.new(0, 255, 0) elseif game.Players.LocalPlayer.Team == purple then script.Parent.BrickColor = BrickColor.new(170, 0, 170) end end)
If a player on the green team touches the part, it turns the part green, and if a player on the purple team touches the part, it turns the part purple. This works perfectly in studio, but in-game it doesn't. Please help!
I see two problems with this, but one causing the issue.
connect
is deprecated. Please use Connect
instead
This appears to be in a part. If this is a LocalScript, it needs to be changed to a Script, because LocalScripts do not work in parts. Additionally, LocalPlayer cannot be used in Scripts.
Use this code, it will fix your problem:
script.Parent.Touched:Connect(function(hit) local player=game.Players:GetPlayerFromCharacter(hit.Parent) if player then green = game.Teams.Green purple = game.Teams.Purple if player.Team == green then script.Parent.BrickColor = BrickColor.new(0, 255, 0) elseif player.Team == purple then script.Parent.BrickColor = BrickColor.new(170, 0, 170) end end end)