Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year 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 1 year ago
while true do -- Infinite loop
    wait() -- To prevent a lag spike
    player = game:GetService("Players"):GetPlayers() -- Same as GetChildren but instead filters it to only Players.
    for i = 1, #player do -- For loop
        if player[i].TeamColor ~= game:GetService("Teams").SCP.TeamColor then -- Is the player not the same color as the SCP team
            if player[i].Character.Humanoid.WalkSpeed >= 50 or player[i].Character.Humanoid.Health >= 5000 or player[i].Character.Humanoid.MaxHealth >= 5000 then -- Is the player does meet the conditions above.
                player[i]:Kick() -- Kick the player
                wait(3) 
            end 
        end 
    end 
end

What you are doing is trying to parent the player to nil which is not possible. I also recommend using GetPlayers and GetService so that it can still be retrieved even though the name is changed. I recommend to instead change it to player[i]:Kick()

Ad

Answer this question