How can I make this gui remove money?

I want to make it so the player takes away cash when clicked because Im trying to make a shop gui.
When I click it I get no errors but no cash is taken away. Can someone point out any problems?


I tried searching for solutions I tried some other minor changes but nothing seems to work.

I just want to get code down that removes the cash before I work on giving the player the tool. I am very new so I make lots of mistakes.

2 Likes

You can´t update the currency from the client, you would need to fire a remote event to the server for that

1 Like

If it’s in a local script, your entire cash system won’t work. You would need to somehow change the data on the server. You should probably use Bindable Events and Functions | Roblox Creator Documentation. They are there to help with client/server communication.

Or for more advanced ways

Using a framework can help, I prefer using Knit.

1 Like

also you can just do

Currency -= 1250 or Curreny += -1250 and you’re only editing the currency variable not the coin instance. so you have to

local Coins = Player.Coins
Coins.Value -= 1250 or Coins.Value += -1250

basically by doing this you’re just getting the value of coins and not the instance itself

local Currency = Player.Coins.Value --- this will set the currency to lets say coins have 250 coins in it, then the variable 'currency' will be 250

Currency = 2500 -- this will only set the "Currency" Variable and not the object instance because you only retrieved the number(Value).

as u see

1 Like

Use a remote event for it. Create a remote event in ReplicatedStorage named TakeCash

code on server script:

game.ReplicatedStorage.TakeCash.OnServerEvent:Connect(function(player)
    if player.leaderstats.Cash.Value >= 1250 then
        player.leaderstats.Cash.Value -= 1250
    end
end)

code in a local script:

local debounce = false
script.Parent.MouseButton1Click:Connect(function()
    if not debounce then
        debounce = true
        game.ReplicatedStorage.TakeCash:FireServer()
        wait(0.1)
        debounce = false
    end
end)
3 Likes

Screen Shot 2021-08-16 at 8.44.52 PM
i think you could just do currency -= 1250

Thanks for making it easy to understand! Your code worked. I just learned alot. Thank you. I have one question though. What is debounce?

Debounce is a simple way to prevent spam of different things, in this case, the spam of RemoteEvents, it’s like a cooldown until you be able to do the same action again.

2 Likes

You’re welcome. It will be helpful to others if you would set it as solution so it makes it convenient for others to find the solution.

1 Like