while wait() do
for _,v in pairs(game.Players:GetChildren()) do
if (v.Character.Head.Position - script.Parent.Position).Magnitude <= 10 then
script.Parent.BrickColor = BrickColor.new("Really red")
else
script.Parent.BrickColor = BrickColor.new("Really black")
end
end
end
The error: [ Workspace.MainPart.Script:3: attempt to index nil with ‘Head’]
The player’s character doesn’t exist when the script references it. The solution is to just wait for the character to load. Above the error line, put this line above it:
local char = v.Character or v.CharacterAdded:Wait()