Money Script doesn't work

Hello guys, it’s me again, today i’m working with a new project…
so, i’ve created a “IntValue” in the leaderstats for player money, and i made a GUI with a tool.
But when i click to buy the tool the Server recieve’s the Signal, but the player money doesnt don’t decrease.

Here’s the Localscript:

local RP = game:GetService("ReplicatedStorage")
local Buy = RP:WaitForChild("Buy")
script.Parent.MouseButton1Click:Connect(function()
Buy:InvokeServer()
end)

And the Serverscript

local replicatedStorage = game:GetService("ReplicatedStorage")
local buy = replicatedStorage:WaitForChild("Buy")

local Bread = 5

buy.OnServerInvoke = function(player)
	print ("Server Event: Bread")

local MoneyP = player.leaderstats.Money.Value

if MoneyP >= Bread then
	MoneyP = MoneyP - 5
	print ("Here's Your Bread")
else
	print ("You not Enough Money")
	end
end

The Server receives the message but when i write MoneyP = MoneyP - 5, the script just doesn’t remove 5 from the player’s money

What can this be?
sorry for the bad English

1 Like

Have you looked to see if there are any errors in the output?

the output:

17:21:47.192 Server Event: Bread - Server - Remotes:7
17:21:47.192 Here’s Your Bread - Server - Remotes:13

I am not sure. You have the correct money leaderstats right?

1 Like

Don’t get the value here

do:

local MoneyP = player.leaderstats.Money

if MoneyP.Value >= 5 then
    MoneyP.Value = MoneyP.Value -5
end

Also why are you using RemoteFunctions and not RemoteEvents?

1 Like

I’ll try to use it thanks…
What is the main difference between RemoteFunctions and RomoteEventes?

Ah I know this. Change this

quote=“Sn1perA, post:1, topic:1279722”]
local MoneyP = player.leaderstats.Money
[/quote]

And here do[quote=“Sn1perA, post:1, topic:1279722”]

if MoneyP >= Bread then
	MoneyP = MoneyP - 5

[/quote]

if MoneyP.Value >= Bread then 
    MoneyP.Value -= 5

For some reason if u do .Value in a variable it doesn’t work

1 Like

omG, what you and the others said (like @NinjaFurfante07) made total sense, thank you really <3

1 Like

The reason is because you’re saving the current value of the intvalue to the variable not the instance

2 Likes