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

Add Cooldown To Teleport To Location Part ?

Asked by
DakuCat -5
4 years ago

Hello I Need your help,can someone add a cooldown to this script,like wait (5) thingy,(i tried to add wait(5) but it doesnt work

Heres the script:

function onTouch(part) local Toucher = part.Parent:FindFirstChild("Humanoid")

if Toucher ~= nil then

Toucher.Torso.CFrame = CFrame.new(-11.97, 0.5, 53.22)--where you place the cordinants and to do that
--you have to place a part then open properties slect the part look at position then put the code in 
--there

end

end

brick = script.Parent brick.Touched:connect(onTouch)

please edit it and just add a cooldown

2 answers

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Adding a wait won't do anything without a debounce. Every time the Touched event is fired, the wait will be ignored. A debounce will prevent the code from running even if the event connects.

local debounce = true
script.Parent.Touched:Connect(function(hit)
    -- Is hit and touchable
    if hit and hit.Parent and debounce then
        -- Is Player?
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Player then 
            -- Is Humanoid
            local Humanoid = Player.Character:FindFirstChild("Humanoid")
            -- Is player alive
            if Humanoid and Humanoid.Health > 0 then
                -- set debounce to prevent spam
                debounce = false
                Player.Character:SetPrimaryPartCFrame ( CFrame.new(-11.97, 0.5, 53.22) )
            end
        end
        wait(3)
        -- reset debounce
        debounce = true
    end
end)
Ad
Log in to vote
-1
Answered by 4 years ago

just add a wait()

if Toucher ~= nil then
Toucher.Torso.CFrame = CFrame.new(-11.97, 0.5, 53.22)

wait()  ---- how long you want to  cool down

end

Answer this question