I want to identify a humanoid with a right leg, and change the brickcolor to Really red. I keep getting this error and I cannot figure out what's wrong. Thanks!
part = script.Parent.Part game.Players.PlayerAdded:connect(function() local plr = {game.Players} for i,v in pairs(plr) do char = v:GetPlayerFromCharacter(plr) if char then hum = char:FindFirstChild("Humanoid") if hum then hum.RightLeg.BrickColor = BrickColor.new("Really red") end end end end)
Notice on line 7 you define hum as a Humanoid. On line 9, the hierarchy is incorrect. You are basically saying that Humanoid.RightLeg.BrickColor = BrickColor.new("Really red")
, which will error because Humanoid does not contain a RightLeg. This should fix the problem:
part = script.Parent.Part game.Players.PlayerAdded:connect(function() local plr = {game.Players} for i,v in pairs(plr) do char = v:GetPlayerFromCharacter(plr) if char then hum = char:FindFirstChild("Humanoid") if hum then hum.Parent.RightLeg.BrickColor = BrickColor.new("Really red") --referring to Humanoid's parent, the Player end end end end)
I hope this helps!
Hey, I read your script and I wasn't exactly sure what you wanted to do 100% so I gave you two examples.
part = script.Parent.Part -- if you want the joining player ONLY to have that right leg red game.Players.PlayerAdded:connect(function(plr) -- When the player joins it is assigned to the variable plr repeat wait() until plr.Character -- waits for the player's character to load to avoid errors if plr.Character:FindFirstChild("Humanoid") then -- checks if the player has a humanoid if so then do : plr.Character.RightLeg.BrickColor = BrickColor.new("Really red"); -- makes the player's Right Leg Really red. end end) -- if you want all the players to have red leg game.Players.PlayerAdded:connect(function() for _, player in pairs(game.Players:GetPlayers()) do -- gets the list of all players in the game once a player joins if player.Character:FindFirstChild('Humanoid') then -- checks if each player has a humanoid player.Character.RightLeg.BrickColor = BrickColor.new("Really red"); -- makes all players that have a humanoid have a Really red Right Leg end end end)