Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what's wrong with this simple loop script? (attempt to index a nil value)

this script checks every second for the torso color then prints their name with it

it works for some seconds but then it stops and gives me error at one of the lines 6, 11, 16





function func()


for _,v in pairs(game.Players:GetChildren()) do

if  v.Character:WaitForChild("Torso").BrickColor == BrickColor.new("Bright green") then -- attempt to index a nil value

print("Bright green: "..v.Name)
end

if  v.Character:WaitForChild("Torso").BrickColor == BrickColor.new("Flint")  then  -- attempt to index a nil value

print("Flint: "..v.Name)
end

if  v.Character:WaitForChild("Torso").BrickColor == BrickColor.new("New Yeller")  then -- attempt to index a nil value

print("New Yeller: "..v.Name)
end

end
end

while wait(1) do
func()
end


1 comment

0

also, for convenience, if something is not what your if statement wants, do elseif.

2 answers

✓ Accepted answer

You should use GetPropertyChangedSignal to detect when the Torso colour changes:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Torso"):GetPropertyChangedSignal("BrickColor"):Connect(function()
	print(tostring(char.Torso.BrickColor) .. ": " .. plr.Name)
end)
	end)
end)

Well R15 doesn't have a Torso so that could be the problem. You can use UpperTorso and LowerTorso instead

1 comment

0

everyone is r6 but thx anyway

This discussion is preserved as it was. New answers, comments, and votes are closed.