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.
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.