Cash System For Vending Machine

So I’m trying to make a vending machine that removes “cash” from the leaderboard.

I’m not sure how to make it take away instead of adding

I tried making it a - sign and making the numbers negative. didn’t work

The main way to get money is from robbing atms so thats why its robbedAmount.



pps.PromptTriggered:Connect(function(pp, plr)


	if pp.Name == "Cola" then

		local robbedAmount = math.random(100, 500)

		plr.leaderstats.Cash.Value += robbedAmount


		pp.Enabled = false

		wait(30)

		pp.Enabled = true
	end
end)

It works giving me money but not taking away. that’s the default script. I’m not sure what to do

What did it look like when you added a minus?

nothing happened. it didn’t raise my money or take it.

Can you paste the code when it had a minus sign?

so far ive tried

local pps = game:GetService("ProximityPromptService")


pps.PromptTriggered:Connect(function(pp, plr)


	if pp.Name == "Cola" then

		local robbedAmount = math.random(-100, -500)

		plr.leaderstats.Cash.Value += robbedAmount


		pp.Enabled = false

		wait(30)

		pp.Enabled = true
	end
end)

-500 is less than -100, try switching those numbers around

1 Like

IVE GOT ITTTTT. I didnt see the +

if pp.Name == "Cola" then

		local robbedAmount = math.random(-100, -500)

		plr.leaderstats.Cash.Value **+**= robbedAmount

I changed that to a - and it worked. thanks for trying to help. my dumbness

2 Likes
math.random(-100, -500)

This is still invalid, you need to switch the two around as suggested (the lowest number of the range of potential random numbers must be less than (or equal to) the highest number of the range of potential random numbers).

math.random(-500, -100)
1 Like
local pps = game:GetService("ProximityPromptService")


pps.PromptTriggered:Connect(function(pp, plr)


	if pp.Name == "Cola" then

		local robbedAmount = math.random(400, 500)

		plr.leaderstats.Cash.Value -= robbedAmount


		pp.Enabled = false

		wait(30)

		pp.Enabled = true
	end
end)

This is whats working for me. I tried what you said and it just gives me money not takes.

I was just letting you know how math.random() works, don’t forget that a number subtracted by a negative number will result in an addition (two negatives make a positive).

1 Like