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

Wait time for player?

Asked by 8 years ago

Hello,

How can I make "Wait" for one player? example, "Bob" touches the button and then he gets 21 Coins, but if "Peter" touches it, he can't get points because of wait(600). How can I make "Bob" example has to wait 600 Seconds before HE can touch it again to gain coins.

Name's were just examples

--Basically checks if the toucher of the button is a player, then adds money to that player.

--Uberubert
--This script is free to use for anyone

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 timers={}
            local a,b=timers[player.Name]or 0,tick()
            if b-a>=600 then
            timers[user.Name]=b
            local cash = stats:findFirstChild("Points") --Get money
            cash.Value  = cash.Value +300 --increase amount of money by the number displayed here (500)
    ting = 0 --remove debounce

script.Parent.Touched:connect(onTouched)
end
        end
    end
    end
end

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

You can store times in a table and check the corresponding index when someone touches the button.

local timers={}
script.Parent.Touched:connect(function(hit)
    local player=game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local a,b=timers[player.Name]or 0,tick()
        if b-a>=600 then
            timers[player.Name]=b
            player.leaderstats.Points.Value=player.leaderstats.Points.Value+300
        end
    end
end)
0
I added code for you. How should I do it? Maamees13 5 — 8y
0
edited 1waffle1 2908 — 8y
Ad

Answer this question