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

I'm making a delivery service job for a game, how do I do this?

So a little more in depth... I am a beginner scripter and I am trying to make it so players can pickup an object from one point and they have to deliver it to another location for money. I have it figured out to where the destination takes away the object and gives money, but after the deliver it they can still stand on the destination brick and get money, is there any way I can make a cool down?

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if plr then
			local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
			plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10
			for i,v in pairs(holders) do
				pcall(function()
					for i,v in pairs(v:GetChildren()) do
						if v:IsA("BackpackItem") then
							v:Destroy()
						end
					end
				end)
			end
		end
		debounce = false
	end
end)

1 answer

✓ Accepted answer

You can just put a wait before you set the debounce to false

so it would look like

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if plr then
            local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
            plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10
            for i,v in pairs(holders) do
                pcall(function()
                    for i,v in pairs(v:GetChildren()) do
                        if v:IsA("BackpackItem") then
                            v:Destroy()
                        end
                    end
                end)
            end
        end
	wait(60)
        debounce = false
    end
end)

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