How would you make this so the gift would respawn after 5 minutes?
01 | amnt = 1 |
02 | function 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 |
17 | end |
18 |
19 | script.Parent.Touched:connect(onTouched) |
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.
01 | amnt = 1 |
02 |
03 | local deb = false |
04 | function 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 |