game.Players.PlayerAdded:Connect(function(plr)
local humanoid = plr.Character:FindFirstChild("Humanoid")
end)
I have this code and it keeps outputting:
Does anyone know why?
game.Players.PlayerAdded:Connect(function(plr)
local humanoid = plr.Character:FindFirstChild("Humanoid")
end)
I have this code and it keeps outputting:
Does anyone know why?
Use :WaitForChild() instead, as sometimes :FindFirstChild() will fail.
The player’s character does not exist right as the player joins, so you will have to wait for it, then you can use :FindFirstChild(“Humanoid”) on it
This means the character has not loaded yet so the script does not recognise it as being there.
You can fix this by running the code with the character has been fully loaded by doing the following:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = plr.Character:FindFirstChild("Humanoid")
end)
end)
This will run as soon as the character is fully added, instead of having to manually add a wait()
when you can’t determine exactly how long the character will take to load.
That’s a really bad approach. Please don’t rely on it being three seconds. When they load in in less time, they’ll have to wait for your script to wait that arbitrary number. What if they reset when they spawn in, breaking it? On the other hand, when they take longer to load in, your script straight up breaks. Do an event based approach like Legend suggested.