The problem is the following, I have an amount of money (50$), I will buy a hamburger that costs 50$, ok I am now left with 0$ but then I go to work and supposedly I would have 5$ but I end up getting 55$. I don’t know what is the problem itself but please someone help.
Scripts:
Vending Machine:
local Button = script.Parent
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cooldown = 30
local function buyItem()
local humanoid = Player.Character:FindFirstChild("Humanoid")
local salario = Player.leaderstats.Salario
local isCoolingDown = Button.Cool.Value
if not isCoolingDown and salario.Value >= 50 then
local tool = ReplicatedStorage.Tools.Hamburguer:Clone()
tool.Parent = Player.Backpack
salario.Value -= 50
humanoid.Health -= 25
Button.BorderColor3 = Color3.new(1, 0, 0)
Button.Cool.Value = true
wait(cooldown)
Button.Cool.Value = false
Button.BorderColor3 = Color3.new(0, 1, 0)
end
end
Button.MouseButton1Click:Connect(function()
buyItem()
end)
Work Script:
local Prom = script.Parent
Prom.Triggered:Connect(function(player)
if player.TeamColor == BrickColor.new("Maroon") then
local Item = player.Backpack:FindFirstChild("Correio")
if Item then
Item:Destroy()
local leaderstats = player:WaitForChild("leaderstats")
local Salario = leaderstats:WaitForChild("Salario")
Salario.Value = Salario.Value + 5
end
end
end)
Image: