I I keep getting my money back after working

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:

image

Use a RemoteEvent and then lower values on the server.

There isn’t any other way without being remote event?
I’m not familiar using these.

Nope, the server has to see that you are lowering those values.

Well damn, btw thanks for responding the Post. I’m will try fix it, incase I succed. I will put your comment as Solution

1 Like

The Remote Event worked. Thank you for your help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.