I’m trying to make a cola game, but when you buy a lot of stuff, it gives you negative cash, but players can still buy stuff, but they will go in debt even more, I want to add it where, if you dont have enough money, it wont let you buy it.
this is the leaderboard script:
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new(“IntValue”)
stats.Name = “leaderstats”
stats.Parent = p
script.Parent.ClickDetector.MouseClick:connect(function(player)
if player:FindFirstChild(“leaderstats”) then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 50 – price of the item
game.Lighting.Cheeto:Clone().Parent = player.StarterGear
game.Lighting.Cheeto:Clone().Parent = player.Backpack
end
end)
script.Parent.ClickDetector.MouseClick:connect(function(player)
if player:FindFirstChild(“leaderstats”) then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 50 – price of the item
game.Lighting.Cheeto:Clone().Parent = player.StarterGear
game.Lighting.Cheeto:Clone().Parent = player.Backpack
end
end)
This should work, sorry im on mobile and I cannot test this in studio /:
local itemCost = 50 --This is how much the item costs
script.Parent.ClickDetector.MouseClick:connect(function(player)
if player:FindFirstChild(“leaderstats”) then
if player.leaderstats.Cash.Value >= itemCost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - itemCost
game.Lighting.Cheeto:Clone().Parent = player.StarterGear
game.Lighting.Cheeto:Clone().Parent = player.Backpack
end
end
end)
Edit: I made a mistake and did player.leaderstats.Value instead of player.leaderstats.Cash.Value
This is fixed now
local itemCost = 50 --This is how much the item costs
script.Parent.ClickDetector.MouseClick:connect(function(player)
if player:FindFirstChild("leaderstats") then
if player.leaderstats.Cash.Value > itemCost or player.leaderstats.Cash.Value == itemCost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - itemCost
game.Lighting.Cheeto:Clone().Parent = player.StarterGear
game.Lighting.Cheeto:Clone().Parent = player.Backpack
end
end
end)