Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Script is taking currency and putting people into the negative?

Asked by
lomo0987 250 Moderation Voter
10 years ago

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

Log in to vote
3
Answered by
wrenzh 65
10 years ago

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.

0
Did this work? wrenzh 65 — 10y
0
Lol, I don't know why i didn't see this in the first place.. lol thanks, it should work now XD lomo0987 250 — 10y
0
You're welcome. wrenzh 65 — 10y
0
Remember it should really be >=, or else I can't buy a $1 thing with $1! BlueTaslem 18071 — 10y
Ad

Answer this question