Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script is taking currency and putting people into the negative?

It takes the currency if they are under the cost and they go negative. I don't know what I did wrong but everything works besides that.

local PointsService = Game:GetService("PointsService")
local ting = 0 
local Cost = 20000 


function onTouched(hit)

if ting == 0 then 
ting = 1 
print("It got past the tings")
check = hit.Parent:FindFirstChild("Humanoid") 

if check ~= nil then 
print("check is not nil")

local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
local stats = user:findFirstChild("leaderstats") 

if stats ~= nil then 
print("stats is not nil")
local cash = stats:findFirstChild("Cash")
if cash.Value > cash.Value - Cost then 
print("Value of cash is fine")
cash.Value = cash.Value - Cost 
print("Made the sale")
PointsService:AwardPoints(user.userId, 1)
print("Awarded points")

wait(5)
end
end
end

ting = 0 
print("Ting back to 0")
end

end

script.Parent.Touched:connect(onTouched)

1 answer

Your problem is with cash.Value > cash.Value - Cost

Let me explain:

Say the person has 10000 Cash and this costs 20000.

10000-20000 is -10000.

10000 > -10000, so the script still executes. I suggest you switch to cash.Value > Cost

So, if the person has 10000 Cash, 10000 is not greater than 20000 and it doesn't execute.

4 comments

0

Did this work?

0

Lol, I don't know why i didn't see this in the first place.. lol thanks, it should work now XD

0

You're welcome.

0

Remember it should really be >=, or else I can't buy a $1 thing with $1!

This discussion is preserved as it was. New answers, comments, and votes are closed.