Ad
Log in to vote
0

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

Asked by 14 days ago

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

Log in to vote
0
Answered by 2 days ago
Edited 2 days ago
--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..

Ad

Answer this question