So Im trying to grab the players character with a server script, I know I should be using a local script, but I thought it was worth a shot.

while wait(0.1) do
for i,v in pairs(game.Players:GetChildren()) do
print(v.Character)
	
			
end
end

So the code I posted above works fine, it prints the characters name.

but when I add the Humanoid it gives me nil.

while wait(0.1) do
for i,v in pairs(game.Players:GetChildren()) do
print(v.Character.Humanoid)
	
			
end
end

The error it gives is
16:45:23.232 - ServerScriptService.GetPlayers:6: attempt to index nil with 'Humanoid'

So what I don't understand is how can it get the character but not the humanoid?

5 comments

0

use :WaitForChild()

0

print(v.Character:WaitForChild("Humanoid"), as of what @b_mni said.

0

That just give me the error "17:08:38.617 - ServerScriptService.GetPlayers:3: attempt to index nil with 'WaitForChild'"

0

It prints nil a few times with your first script. You are gonna need a way to wait for the character to be loaded in too

0

Ah yes it now works, thank you!