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

Leaderboard money goes to Minus (-)?

Asked by
kilu6n 0
7 years ago

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)

0
Do you mean it goes into the negative? Is that not what you wanted it to do? I need you to reword the question. User#18718 0 — 7y
0
the ting goes skrrraa creeperhunter76 554 — 7y
0
Change 'cash.Value = cash.Value -100' to 'cash.Value = cash.Value - 100' NetworkEngineer 0 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

0
I've legitimately seen this script before in a free model. You can see for yourself by searching up "money giver" in the toolbox creeperhunter76 554 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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)

Answer this question