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?
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.
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).
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)
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.