local awardGold = Instance.new("BindableEvent", script.Parent)
awardGold.Name = "awardGold"
awardGold.Event:connect(function(player, goldGiven)
if player and goldGiven then
local myData = playerData[player.userId]
if myData then
if gamePassService:PlayerHasPass(player, goldID) then
myData.gold = myData.gold + (goldGiven * 3)
local goldValue = player.PlayerFolder:WaitForChild("Gold")
if goldValue then
goldValue.Value = myData.gold
end
else
myData.gold = myData.gold + goldGiven
local goldValue = player.PlayerFolder:WaitForChild("Gold")
if goldValue then
goldValue.Value = myData.gold
end
end
end
end
end)
if myData.gold >= cost then
script.Parent.awardGold:Fire(player, -cost) -- Taking away the gold from their balance
purchase(item, itemName, player)
buyEvent:FireClient(player, true)
end
I’m having problems with my gold awarding system. Players have informed me that they have gotten negative amounts of money, which should be impossible. I check to see if myData.gold >= cost, which myData is the data store. and then cost is the, well cost. So logically the awardGold event shouldn’t be fired unless they have enough money. Is there some way I can check to see why this is happening? I haven’t seen it myself, but I’ve had players SS and show me, so I know that some how players are getting less than 0 gold.
Is your game experimental mode? If it is, somehow they (or their local scripts) could be modifying the gold so it is below 0. You should also look through all of your server-side scripts to make sure it’s not one of them, either.
But, just as a precaution, clamp the value of the gold every time you change it (or it gets changed), for example:
And this seems, to me, exactly what your issue is too, @NinjoOnline.
First of all, big oversight on making players spend more for owning the gamepass. However, in the future, make sure it checks how much they will have to spend, and not the price of it. By checking the price rather than how much the player spends, it forces you to rearrange your system later if you end up adding things that could potentially lower the price of an item.
However, back onto your issue, an easy fix would be to switch this:
if gamePassService:PlayerHasPass(player, goldID) then
To this:
if goldGiven > 0 and gamePassService:PlayerHasPass(player, goldID) then
OMG, this was a massive oversight! The reason why gamepass was *3 is because I use that event to add gold to the players balance, so the pass was to give you 3 times the amount normally given. Completely didn’t realise that it was also affecting the negatives as well!
Nope. Min picks the smaller number. Max picks the bigger number. I mix them up all the time (and edited my post a minute after I posted it because I did it again).
They actually only take up to 8000 arguments (an important lua limitation to know about if you ever find yourself unpacking arbitrary-length tables.)
for argCount = 7995, 8005 do
print("Testing", argCount)
local list = {}
for i = 1, argCount do
list[i] = i
end
print("Result", math.max(unpack(list)))
end