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

2 comments
Please take a look at this blog:- https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online.
"Checked the blog post, nothing worked, though."