So I created 2 scripts, one where it gives you 10 cash every 10 seconds and one script where when you click a button it gives you a snowball and it subtracts 10 cash from you.
Whenever I purchase the snowball, when the cash increase script loops back, it gives me 20 cash. If I purchase 10 snowballs it gives me 110 cash. Why is this happening??
Here is the script for my cash increase:
-- Variables -- mintime = 10 -- Coding -- local function onPlayerJoin(player) while true do wait(mintime) local cash = player.leaderstats.Cash cash.Value = cash.Value + 10 end end game.Players.PlayerAdded:Connect(onPlayerJoin)
Here is the script for my purchasing: The value for the price is 10 and the value for the item is Snow ball.
button = script.Parent item = script.Parent.ItemInGame.Value price = script.Parent.Price.Value script.Parent.ItemInGame.Changed:Connect(function() item = script.Parent.ItemInGame.Value end) script.Parent.Price.Changed:Connect(function() price = script.Parent.Price.Value end) button.MouseButton1Click:connect(function() local player = game.Players.LocalPlayer if player.leaderstats.Cash.Value >= price then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 10 game.Lighting[item]:Clone().Parent = player.Backpack elseif player.leaderstats.Cash.Value < price then button.Text = "Not Enough Money!" wait(1.5) button.Text = "Purchase" end end)