Ayd3nL
(Ayden)
February 7, 2022, 2:54am
#1
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?
Ayd3nL
(Ayden)
February 7, 2022, 3:03am
#3
nothing happened. it didn’t raise my money or take it.
Can you paste the code when it had a minus sign?
Ayd3nL
(Ayden)
February 7, 2022, 3:11am
#5
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
Ayd3nL
(Ayden)
February 7, 2022, 3:14am
#7
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
Forummer
(Forummer)
February 7, 2022, 11:58am
#8
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
Ayd3nL
(Ayden)
February 7, 2022, 11:30pm
#9
Forummer:
math.random(-500, -100)
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.
Forummer
(Forummer)
February 8, 2022, 12:31am
#10
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