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

A random error appears when only 2 or more players join the game?

Asked by 4 years ago
Edited 4 years ago

I was running some testing in my local server with just 2 players, and I've been getting this error for some players. This script works perfectly fine for solo testing, but not many players?

Workspace.Player1.LocalScript:2: attempt to index field 'Character' (a nil value)

Here is my script.

for _, v in pairs(game.Players:GetPlayers()) do
    if v.Character.Humanoid.Health == 0 then --The error showed me this line.
        workspace.Players[v.Name]:Destroy()
    end
end
1
Make a code block for if the character exists. A Player can still be in a game without a Character, therefor, the player's character will be nil. pidgey 548 — 4y
0
I'll look into it. User#27966 0 — 4y
0
I got it! Thank you so much. I wish I can upvote you but I can't because I don't have enough reputation. ;-; User#27966 0 — 4y

Answer this question