Hello! I have been creating a shop for the past few hours, but there's a problem: the money goes back up in a second after you purchase something. So, let's say there is something in the shop for 1 thousand cash, and you buy it and expect for your money to go down. Except the opposite happens. You have 5 thousand cash and you purchase the gear for 1 thousand. The money goes down to 4 thousand for a few seconds, then goes back to 5 thousand. I have a currency riser in the game, but it increases the value by 30 each 1 second. Heres the currency riser script:
while true do wait(1) player.leaderstats[valueName].Value = player.leaderstats[valueName].Value + 30 end
And heres the shop script:
script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.Parent.Parent.Clicked:Play() if game:GetService("Players").LocalPlayer.leaderstats["Money"].Value <= 1001 then game:GetService("Players").LocalPlayer.leaderstats["Money"].Value = game:GetService("Players").LocalPlayer.leaderstats["Money"].Value - 1000 local balloon = game.Lighting.RedBalloon:Clone() balloon.Parent = game.Players.LocalPlayer.Backpack end end)
All help will be appreciated! :)
If you change the values from a localscript it will only change the value from the client, you should use remote events to change the values from the server.
LocalScript
script.Parent.MouseButton1Click:Connect(function() local replicatedstorage = game:GetService("ReplicatedStorage") local PurchaseRemote = replicatedstorage.PurchaseRemote --Add a remoteevent into replicatedstorage named PurchaseRemote script.Parent.Parent.Parent.Parent.Parent.Clicked:Play() if game:GetService("Players").LocalPlayer.leaderstats["Money"].Value <= 1001 then PurchaseRemote:FireServer() end end)
Normal Script
local replicatedstorage = game:GetService("ReplicatedStorage") local PurchaseRemote = replicatedstorage.PurchaseRemote PurchaseRemote.OnServerEvent:Connect(function(player) player.leaderstats.Money.Value = player.leaderstats.Money.Value - 1000 local balloon = game.Lighting.RedBalloon:Clone() balloon.Parent = game.Players.LocalPlayer.Backpack end)