I'm working on a game that allows blocks you touch to change colour based on your team colour, I was wondering what was wrong with this script that did not allow it to work in online mode. In test mode in studio it works perfectly. This is in a normal script in the part;
function onTouch(hit) local player = game.Players.LocalPlayer if player.TeamColor == BrickColor.new("Really red") then script.Parent.BrickColor = BrickColor.new("Really red") elseif player.TeamColor == BrickColor.new("New Yeller") then script.Parent.BrickColor = BrickColor.new("New Yeller") elseif player.TeamColor == BrickColor.new("Lime green") then script.Parent.BrickColor = BrickColor.new("Lime green") elseif player.TeamColor == BrickColor.new("Toothpaste") then script.Parent.BrickColor = BrickColor.new("Toothpaste") elseif player.TeamColor == BrickColor.new("Really blue") then script.Parent.BrickColor = BrickColor.new("Really blue") elseif player.TeamColor == BrickColor.new("Hot pink") then script.Parent.BrickColor = BrickColor.new("Hot pink") end end script.Parent.Touched:connect(onTouch)
I've experienced this problem before with click detectors, and without a solution none of my games are working. Please send help :c
Because Local Scripts
don't work in workspace, we'll use the GetPlayerFromCharacter
function of the Players Service
.
function onTouch(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent)-- Gets player if player then-- Makes sure player exists if player.TeamColor == BrickColor.new("Really red") then script.Parent.BrickColor = BrickColor.new("Really red") elseif player.TeamColor == BrickColor.new("New Yeller") then script.Parent.BrickColor = BrickColor.new("New Yeller") elseif player.TeamColor == BrickColor.new("Lime green") then script.Parent.BrickColor = BrickColor.new("Lime green") elseif player.TeamColor == BrickColor.new("Toothpaste") then script.Parent.BrickColor = BrickColor.new("Toothpaste") elseif player.TeamColor == BrickColor.new("Really blue") then script.Parent.BrickColor = BrickColor.new("Really blue") elseif player.TeamColor == BrickColor.new("Hot pink") then script.Parent.BrickColor = BrickColor.new("Hot pink") end end end script.Parent.Touched:connect(onTouch)
Good Luck!