There is this bug where when I try to add to an IntValue, it resets the value to 0. I would expect that it continue off from the original value, but it sets it to 0.
The bug usually happens most of the time, there are some times where it does work, but most of the time the value has reset to 0 and adds from there.
Here is part of my script just in case you believe it is not a bug
player.Fatbux.Value = player.Fatbux.Value + 1000
while mex.Value ~= player.Fatbux.Value do
if db == true then
mex.Value = mex.Value + 5
wait(0.01)
if mex.Value == player.Fatbux.Value then
db = false
break
end
end
end
This bug happens in my game when I go to test purchase the “fatbux”.
Here is a video
The bug started happening when I finished the script, and I have struggled to find out why this is happening, so that is why I came to it thinking it was a bug. (I am sorry if this is not a bug and it is a script error).
There are no other scripts that change the “mex” Value to 0, I have checked multiple times. Thank you to anyone who can help!
What is this “mex” value? Can you show more context around the script?
Try printing mex.Value before the while loop. Is it zero before the loop begins?
Sorry for the long wait, the mex value is a value I use to add the cool cash effect to the “Fatbux” GUI, so that way it saves the actual value with what a player bought instead of a random value when they leave the game. Here is the def of it at the top of the script:
game.Players.PlayerAdded:Connect(function(player)
local mex = player:WaitForChild("display")
it is zero before the loop starts, can you tell me why this is.
Here is the full part of the script:
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
-- code here
elseif receiptInfo.ProductId == 755489961 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.Fatbux.Value = player.Fatbux.Value + 1000
print(mex.Value)
while mex.Value ~= player.Fatbux.Value do
mex.Value = mex.Value + 5
wait(0.01)
if mex.Value == player.Fatbux.Value then
break
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
-- finishing code here
it only turns to 0 when I make the purchase too. otherwise before that It gets set to the “fatbux” value.
Here’s another way to do this:
local AmountToAdd = 100
local PlayerCash = player.leaderstats.Cash
local CashToAdd = 5
for i = 1,AmountToAdd,CashToAdd do
PlayerCash.Value = PlayerCash.Value + CashToAdd
wait()
end
I tested it using a ClickDetector:
Hope this helps!.
There must be something in the code you’re not showing that’s causing the issue. ValueObjects aren’t broken, so there’s probably a point in your script where you accidentally set it to zero, or some variable that’s equal to zero. It’s a bit difficult to help you when we don’t have the full context of the script.
well that whole script is just a bunch of purchases from dev products, there is not much that is different about the rest of the script. and I have looked through other scripts, but I have found nothing that changes it to 0. I think I might try @geovanny4567 idea and see if that works to clean some stuff up.
also @geovanny4567 I use another value that I called “mex” so when the game saves a player’s cash, it saves the amount of cash of what they bought not what is shown when the player leaves the game. But thanks for the idea to clean some stuff up.
apparently when I do the purchase, it only changes “mex” to 0 the first time. Not anytime after that
something is changing it to 0, but I do not know what. I need to look into some other scripts I have edited.
oh I know now! I was using the client to change the value instead of the server.
Is it ok to solution your own post guys? I feel like it is not.
It’s fine if you’re the one who actually figured out the solution. 
1 Like
ok thanks for that, I just did not want to get in trouble or have people think of me as a bad person and such.