When I'm trying to make a script that removes amount of money on touch the money goes to minus (-) when you don't have enough.
local ting = 0
function onTouched(hit)
if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("money") cash.Value = cash.Value -100 wait(3) end end ting = 0 end
script.Parent.Touched:connect(onTouched)
Creeperhunter76 How can you prove that its a free model? Also kilu6n use this script:
local ting = 0 --debouncer function onTouched(hit) if ting == 0 then --check for debounce ting = 1 --activate debounce check = hit.Parent:FindFirstChild("Humanoid") --try to find the human that touched the button if check ~= nil then --if toucher is a human then to following local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human local stats = user:findFirstChild("leaderstats") --Find moneyholder if stats ~= nil then --If moneyholder exists then local cash = stats:findFirstChild("Money") --Get money cash.Value = cash.Value - --How much you want, remove this end end ting = 0 --remove debounce end end script.Parent.Touched:connect(onTouched) --start checking for touchers
In this case it can be solved using a simple check to see if the value will still be positive once subtracted, adjustment can be seen on line 14:
function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("money") if ((cash.Value - 100) > 0) then cash.Value = cash.Value -100 wait(3) end end end ting = 0 end end script.Parent.Touched:connect(onTouched)