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

Attempt to index nil with 'leaderstats'?

Asked by 3 years ago

I am making a zombie shooting range game that has levels. Whenever I try to access the leaderstats level value it returns the error: Attempt to index nil with 'leaderstats'. Here is the code:

game.Workspace["Shooting range"].LevelSeven.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player:WaitForChild("leaderstats").Level.Value == 7 then
        remote3:FireClient(player)
    end
end)

If you need anything extra just let me know.

1 answer

Log in to vote
0
Answered by 3 years ago

Try using:

if player then
    if player:WaitForChild("leaderstats").Level.Value == 7 then
        remote3:FireClient(player)
    end
end

Checking if the player actually exists, if the GetPlayerFromCharacter function was successful

Ad

Answer this question