Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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
0
also, for convenience, if something is not what your if statement wants, do elseif. User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)
Ad
Log in to vote
0
Answered by 6 years ago

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

0
everyone is r6 but thx anyway LIGHTBOMBS 4 — 6y

Answer this question