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?