so my fist code would be this
amount = 1 timedelay = 4 currencyname = "Cash" while true do wait(timedelay) for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount end end end
the second code would be this
MPS = game:GetService("MarketplaceService") id = 553470050 --dev product id local player = game.Players.LocalPlayer script.Parent.Text = "100 Cash" script.Parent.MouseButton1Click:Connect(function() MPS:PromptProductPurchase(player, id) script.Parent.Text = "Purhasing" wait(5) script.Parent.Text = "100 Cash" player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100 end)
When i do an in-game purchase it adds the cash but then the first code updates it back to the original number. how can i keep the first code to update and add the amount its suppose to?
Put RemoteEvent and normal script in your second code
second code
MPS = game:GetService("MarketplaceService") id = 553470050 --dev product id local player = game.Players.LocalPlayer script.Parent.Text = "100 Cash" script.Parent.MouseButton1Click:Connect(function() MPS:PromptProductPurchase(player, id) script.Parent.Text = "Purhasing" wait(5) script.Parent.Text = "100 Cash" script.RemoteEvent:FireServer(player) end)
Third code ( Normal Script )
script.Parent.RemoteEvent.OnServerEvent:Connect(function(abc,player) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100 end)