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)
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.