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

Gift Hunt Script?

Asked by 10 years ago

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

01amnt = 1
02function onTouched(part)
03    local h = part.Parent:findFirstChild("Humanoid")
04    if (h~=nil) then
05        local thisplr = game.Players:findFirstChild(h.Parent.Name)
06        if (thisplr~=nil) then
07            local stats = thisplr:findFirstChild("leaderstats")
08            if (stats~=nil) then
09                local score = stats:findFirstChild("Gifts")
10                if (score~=nil) then
11                    score.Value = score.Value + amnt
12                end
13            end
14        end
15        script.Parent:remove()
16    end
17end
18 
19script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 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.

01amnt = 1
02 
03local deb = false
04function onTouched(part)
05    if deb then return end
06    deb = true
07    local h = part.Parent:findFirstChild("Humanoid")
08    if (h~=nil) then
09        local thisplr = game.Players:findFirstChild(h.Parent.Name)
10        if (thisplr~=nil) then
11            local stats = thisplr:findFirstChild("leaderstats")
12            if (stats~=nil) then
13                local score = stats:findFirstChild("Gifts")
14                if (score~=nil) then
15                    score.Value = score.Value + amnt
View all 27 lines...
Ad

Answer this question