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)

11 comments
You told it to add not subtract the price
Where?
If you're talking about the first script, that script is supposed to give the player 10 cash every 10 seconds automatically.
You should not be storing tools in lighting or any place the client has access. Also you should not me changing the values in a local script
as kingdom said you cant change cash in a local script, you'll need to use a server script or a remote event
If I do it in a normal script it doesn't work. The first one was already a normal script but the second one was a local script. I made it a normal script and it doesn't work.
of course it didnt. the easiest way will be to use a remote event on line 16 where you're removing the cash.
I am using values so it knows what item the player is purchasing, how would the remote event know what item is being purchased?
you pass the information
Thanks! It worked.
please mark as [Solved]