I'm trying to change the color of a part if a player is within 40 studs. It works on studio, but not in a server.
local plrs={} game.Players.PlayerAdded:connect(function(player) table.insert(plrs,player) end) local part=script.Parent.Ball while wait() do for i,v in pairs(plrs) do if (v.Character.Torso.Position-part.Position).magnitude>40 then script.Parent.Ball.BrickColor=BrickColor.new("Shamrock") script.Parent.Eye1.BrickColor=BrickColor.new("Forest green") script.Parent.Eye2.BrickColor=BrickColor.new("Forest green") elseif (v.Character.Torso.Position-part.Position).magnitude<=40 then script.Parent.Ball.BrickColor=BrickColor.new("Really red") script.Parent.Eye1.BrickColor=BrickColor.new("Maroon") script.Parent.Eye2.BrickColor=BrickColor.new("Maroon") end end end
I fixed when that happened to me by putting a "wait(.1)" at the top of the script. Good luck!