Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gift Hunt Script?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.