When a player buys a tool from gui, it subtracts their coins from leaderstats.
The problem is that when I subtract coins from the server side, the value still doesn’t go down.
I tried to debug it by subtracting it by 100 and not the amount, I also looked for similar forum post’s but they were either subtracting it from the local server or some other problem.
I’m using a function for the local server and a remote for the server script.
Local Server:
local function handleCoins(amount, request)
subtractCoins:InvokeServer(amount, request)
end
Server:
coinHandler.OnServerInvoke = function(player, amount, request)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins").Value
if request == "Subtract" then
coins = coins - amount
end
if request == "Add" then
coins = coins + amount
end
end
This line creates a local variable coins that stores the value of Coins. Any changes you make to coins only affect this local variable, not the actual Coins object in leaderstats.
You’re supposed to set Value of the numbervalue to the coins variable.
@SyntaxMenace Already solved it, but another thing is that, as long as i know the functions InvokeServer() and OnServerInvoke are for Remote Functions, so if you are using a RemoteEvent, instead use FireServer()
and OnServerEvent
I can be wrong, if i am you are free to correct me.
Have a nice day!