Hello!
I have a script that makes an effect on the screen to add coins, rather than just changing the text to the new value.
The issue is that right after the second purchase, the value reverts to the old one.
Purchase Handler Script
m = game:GetService("MarketplaceService")
m.PromptProductPurchaseFinished:Connect(function(userid, productid, purchased)
local player
if purchased == true then
for i,v in pairs(game.Players:GetChildren()) do
if v.UserId == userid then
player = v
end
local value = game.ServerStorage.ProductInfo[productid].Value
game.ReplicatedStorage.CoinAdded:Fire(game.Players[player.Name].inventory.Coins.Value, value, player) -- Player's coin value, value to add, and the player
end
end
end)
Script to update player's coins, gets the old one, should set the new one.
game.ReplicatedStorage.CoinAdded.Event:Connect(function(coinobj, coinstoadd, player)
local oldcoin = coinobj
local newcoin = coinobj + coinstoadd
coinobj = newcoin
print(oldcoin.."oldcoin "..newcoin.."newcoin")
game.ReplicatedStorage.CoinEffect:FireClient(player, oldcoin, newcoin)
end)
Script to update the text on the player's screen.
game.ReplicatedStorage.CoinEffect.OnClientEvent:Connect(function(oldcoin, newcoin)
for i = oldcoin, newcoin, 10 do
script.Parent.Text = "Coins: "..i
wait()
end
end)