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

Where should I put a "wait ()"?

Asked by 9 years ago

Hello, here I have my upgraded instant campfire script and was wondering where to put a "wait ()" to make the player wait before they can use it again? I have my own asset so that will not be the problem.

local Tool = script.Parent
local CurrentCampfire = Tool:WaitForChild('CurrentCampfire')
local Mouse = nil

local InsertService = game:GetService('InsertService')

local CAMPFIRE_ASSET_ID = 0
local SMALL_OFFSET = Vector3.new(0, 1, 0)
local LARGE_OFFSET = Vector3.new(0, 1500, 0)

local function OnActivated()
    if Mouse then
        local character = Tool.Parent
        if character then
            local humanoid = character:FindFirstChild('Humanoid')
            if humanoid and not humanoid.Sit then   
                local hitLocation = Mouse.Hit
                local previousCampfire = CurrentCampfire.Value
                if previousCampfire then previousCampfire:Remove() end
                local campfire = InsertService:LoadAsset(CAMPFIRE_ASSET_ID):GetChildren()[1]
                CurrentCampfire.Value = campfire
                campfire.Parent = Workspace

                humanoid.Died:connect(function() campfire:Destroy() end)
                campfire:MoveTo(hitLocation.p + SMALL_OFFSET)
                Tool.Handle.Drop:Play()
            end
        end 
    end
end

local function OnEquipped(mouse)
    if mouse then
        Mouse = mouse
    end
end

local function OnUnequipped()
end

Tool.Activated:connect(OnActivated)
Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Adding a single delay will not prevent OnActivated from running a second time. You need to add a variable and make sure that it is true before executing the rest of the function, set it to false when it is run, and then after a delay, set it back to true.

0
I haven't seen you on here very often EzraNehemiah_TF2 3552 — 9y
0
LordDragonZord this is not a place for discussion DevChris 235 — 9y
Ad

Answer this question