I'm making a shop and I wanted to make it so that when you have 300 cash, you can buy a moveset.
The problem is that when I buy something, it takes away cash but then as soon as it adds cash, it gives all the cash it took away back.
Here is a video showing what it does: https://www.youtube.com/watch?v=jIRrJ8iAE7g&feature=youtu.be&ab_channel=DankDesmondo
And heres my code:
Giving the currency script
game.Players.PlayerAdded:Connect(function(player) local Value = Instance.new("NumberValue", player) Value.Name = "Currency"
while wait(10) do
Value.Value = Value.Value + 300
end
end)
Buying Things script
script.Parent.MouseButton1Down:Connect(function()
if Player:WaitForChild("Currency").Value >= 299 then
game.ReplicatedStorage:FindFirstChild("BH"):Clone()
game.ReplicatedStorage.BH.Parent = Player.Backpack
Player:WaitForChild("Currency").Value = Player:WaitForChild("Currency").Value - 300
end end)

2 comments
Thanks, it worked.
Please accept the answer if it helped.