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

Gift Hunt Script?

Asked by 9 years ago

How would you make this so the gift would respawn after 5 minutes?

amnt = 1
function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Gifts")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                end
            end
        end
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Right now, this destroys itself permanently when it's "removed". What we need to do instead is Parent it to ServerStorage for 5 minutes.

Additionally, it's a good idea to add some debounce here, so that people can't accidentally trigger it twice.

amnt = 1

local deb = false
function onTouched(part)
    if deb then return end
    deb = true
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Gifts")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                end
            end
        end
    script.Parent.Parent = game:GetService("ServerStorage")
        --script.Parent:remove()
    wait(5*60) -- 5 minutes
    script.Parent.Parent = workspace
    end
    deb = false
end

script.Parent.Touched:connect(onTouched)
Ad

Answer this question