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

Workspace.OrangeParticle.ShopScript:10: attempt to index nil with 'leaderstats'. Why is this?

Asked by 2 years ago

I'm trying to make a shop script and I get this error in the output: Workspace.OrangeParticle.ShopScript:10: attempt to index nil with 'leaderstats'.

OrangeBuyer.Touched:Connect(function(player)
    local Player = player.Parent
    local PlayerTouched = Players:FindFirstChild(Player)

    print(PlayerTouched)
    if PlayerTouched.leaderstats.Wins.Value >= 1 then

    else
        print("You do not have enough wins for this item.")
    end
end)

Please give me the answer and a quick explanation for me to learn from my mistake.

1 answer

Log in to vote
1
Answered by 2 years ago
OrangeBuyer.Touched:Connect(function(player)
    local Player = player.Parent
    local PlayerTouched = Players:FindFirstChild(Player.Name)

    print(PlayerTouched.Name)
    if PlayerTouched.leaderstats.Wins.Value >= 1 then

    else
        print("You do not have enough wins for this item.")
    end
end)

What your mistake is that in line 3 you directly referenced the Character Instance, instead of it's Name. What you had to do instead is write Player.Name to get the name instead of object. I have fixed it for you.

Ad

Answer this question