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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
dispeller 200 Moderation Voter
6 years ago

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)
Ad

Answer this question