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

Need Help Making Script That When A Player Already Touched They Cant Touch Again?

Asked by 6 years ago

So Far In My Script Is

--{jamiethegreatQ777}--

local ting = 0 --debouncer

function onTouched(hit)

    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

    if check ~= nil then --If a human is found, then

        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("Stage") --Get money
            cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (500000)
            wait(5) --wait-time before button works again
        end

    end

    ting = 0 --remove debounce
    end

end

script.Parent.Touched:connect(onTouched)

But The Wait Just Means The Player Can Wait That Long And Just Get Another Stage For Doing Nothing Please Help

1 answer

Log in to vote
0
Answered by 6 years ago
-- Its easy just do this 
--{jamiethegreatQ777}--

local ting = false --debouncer(changed it )

function onTouched(hit)

    if not ting then --debounce check(changes it)
    ting = true  --activate debounce(changed it )

    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

    if check ~= nil then --If a human is found, then

        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("Stage") --Get money
            cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (500000)
            wait(5) --wait-time before button works again
        end

    end

    ting = false --remove debounce(changed it )
    end

end

script.Parent.Touched:connect(onTouched)



0
Thanks :) JamiethegreatQ777 16 — 6y
Ad

Answer this question