Button does not detect the player's leaderstats

Hello developers, I recently made a script to spend money when you press a button, but I do not understand why it does not detect the leaderstats :frowning:


local MoneyNeeded = 2500
script.Parent.MouseButton1Click:Connect(function(player)
local dinero = player.leaderstats:WaitForChild(“Zeni”)

if dinero.Value >= MoneyNeeded then
	dinero.Value -= 2500
else
	print("You don't have enough money")
	script.Parent.Parent:Destroy()
  end
end)

![image|690x26](upload://7cGvBv5AX5JI1RaaatoIMmOFagY.png)
1 Like

MouseButton1Click does not return a parameter / the player. Use LocalPlayer if that is a LocalScript. If it is a serverscript, make a remote and a localscript and fire the remote to perform your check on the serverside.

https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

1 Like

The script is in a server script, but why doesn’t it connect to the leaderstats?

MouseButton1click does not return a player so the player is nil. You need to make it into a localscript, make a remoteevent and do your actions serverside when the remote is fired.