Problem with leaderstats

Whenever I am working with leaderstats, it’s like they don’t even exist!
image
Please help!

The script:

local currencyName = “Cash”
local clickDetector = script.Parent
local player = game.Players.LocalPlayer

function onMouseClick()
script.Parent.Parent.Top.Fire.Enabled = false
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1

end

clickDetector.MouseClick:connect(onMouseClick)

Have you created a folder called leaderstats and set its parent to player?

It would also help if you could show your script that is creating this error

The issue isn’t that leaderstats doesn’t exist, it’s that whatever you’re checking .leaderstats for doesn’t exist. Can you show your code? It’s hard to help you without more context.

3 Likes

If you created leaderstats, you can either WaitForChild() or repeat wait() until so the code doesn’t continue until the leaderstats loaded.

You could try GetPlayerFromCharacter()

Did you name the script “leaderstats” or whatever it is supposed to be?

It is not the fault of leaderstats you should do this server sided so exploiters cant edit your values

Roblox automatically provides the player as a parameter here’s a sample

script.Parent.MouseClick:Connect(function(PartClicked)
      local player = PartClicked.Parent
      player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
end)

The MouseClick event’s parameter is the player who clicked the ClickDetector, not the character.

script.Parent.MouseClick:Connect(function(player)
      player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
end)
1 Like