Coin Handling Problem

Hello! I have recenntly ran into a problem with my script. I am deducting some coins from the player but they are loosing way too much. Sometimes, the player has 10k, spends 1k but looses 5k. Sometimes the player goes into the negatives. Heres where the event is being fired:

local function Boost(ball)
	
	if player.leaderstats.Coins.Value >= 75 and not skillInUse then
		
		skillInUse = true
		
		CoinEvent:FireServer(-75)

Heres the CoinEvent:

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local PlayerData = require(ServerScriptService.PlayerData.Manager)

CoinEvent.OnServerEvent:Connect(function(player, amount)
	local profile = PlayerData.Profiles[player]
	if not profile then return end

	local currentCoins = player.leaderstats.Coins.Value
	local newCoinCount = currentCoins + amount

	if newCoinCount < 0 then
		warn(player.Name .. " went into negative")
		return
	end

	PlayerData.AdjustCoins(player, amount)
end)

Im using PlayerData and I am not sure whats causing this.

Heres where its being fired:

player.PlayerGui.Skills.TopBar.Boost.MouseButton1Click:Once(function()
			disableSkillButtons()
			Boost(ThrownBall)
		end)

This is my first time using :Once, could that be related?

1 Like

You need to use a debounce, quick example.

local debounce = false

part.Touched:Connect(function(hit)
    if debounce then return end
    debounce = true

    print(hit.Name .. " touched part!")
    
    task.wait(1)
    debounce = false
end)

Usually a touched event will fire very rapidly, but as soon as its fired, the first event will set debounce to true, blocking all other instances of the same code from being activated by the event. It will then print something, wait a second, then set debounce to false, allowing the code to be executed again.

Also I can give myself as many coins as I want simply by doing this on the client.

CoinEvent:FireServer(9999999999999999999999)

(The client can execute whatever code they want on their device, but it stays on the client. This does however, give them the ability to fire any event with any values whenever they want)

Also idk abt ur usage of once

1 Like

Hi, Forgot to mention, the skillInUse is a debounce. Also, this is handled by the click of a UI button. Thanks for the help though!