Issue with leaderstats

Hello Developers!

I stuck on this little thing?

What do you want to achieve? I want to make it so when you click a part, it gives you coins in the leaderstats.

The issue? I put in the script but when I played the game, the output had no error but when I clicked it nothing happened?

Script:

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "Leaderstats"
leaderstats.Parent = player

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats

local Coin = game.Workspace.Coin

Coin.ClickDetector.MouseClick:Connect(function()
	Coins.Value = Coins.Value + 1
end)

end)

Thanks for reading!:stuck_out_tongue_winking_eye:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "Leaderstats"
    leaderstats.Parent = player

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = leaderstats
end)


local coinPart = game.Workspace.Coin

coinPart.ClickDetector.MouseClick:Connect(function(playerClicked)
    playerClicked.leadersats.Coins.Value += 1
end)
1 Like

It didn’t work. It just gave an error when I clicked the coin.

What did the error say though?

Gotta love those typos LOL, anyways just change that to leaderstats

OOF. I can’t type these days…

It still doesn’t work.

I have tried another way but it still doesn’t work. Also, the leaderstats didn’t show up.

OH I SEE THE ISSUE! It’s cause you named leaderstats as “Leaderstats”

Always gotta love case-sensitive variables

Try this:

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = leaderstats
end)


local coinPart = game.Workspace.Coin

coinPart.ClickDetector.MouseClick:Connect(function(playerClicked)
    playerClicked.leaderstats.Coins.Value += 1
end)

Thanks for the help! Also saying thanks to Jackscarlett aswell!

1 Like