Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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.

This discussion is preserved as it was. New answers, comments, and votes are closed.