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

Workspace.Script:8: attempt to index nil with 'Humanoid' this is a server script help?

while true do wait() player = game.Players:GetChildren() for i = 1, #player do if player[i].TeamColor ~= game.Teams.SCP.TeamColor then if player[i].Character.Humanoid.WalkSpeed > 50 or player[i].Character.Humanoid.Health > 5000 or player[i].Character.Humanoid.MaxHealth > 5000 then player[i].Character.Parent = nil player[i].Parent = nil wait(3) end end end end

1 answer

--If the players character is loading, or if it doesnt exist (right when they join, or for other reasons) it will return nil, and you won't be able to find the humanoid.

--use this
while true do wait() 
	player = game.Players:GetChildren() 
	for i = 1, #player do
		if player[i].TeamColor ~= game.Teams.SCP.TeamColor then
			local Character = player[i].Character or player[i].CharacterAdded 
			if Character.Humanoid.WalkSpeed > 50 or Character.Humanoid.Health > 5000 or Character.Humanoid.MaxHealth > 5000 then 
				Character.Parent = nil 
				player[i].Parent = nil 
				task.wait(3)
			end
		end
	end 
end

Also, why would you set the player to nil? That in itself would probably cause an error! Also also... Why set the character parent to nil? You can just reduce their health to 0 if you are trying to kill them..

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