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

i want Tool to countdown for 5 seconds?

Asked by
imKlevi 94
5 years ago
Edited 5 years ago

Please help me, whats wrong with this script?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)  
     if key == "z" then
     game.ReplicatedStorage.OpeOpe.Barrier1:Clone().Parent = game.Workspace[player.Name.. "Skills"]
     game.Workspace[player.Name.. "Skills"].Barrier1.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position.X,player.Character.HumanoidRootPart.Position.Y,player.Character.HumanoidRootPart.Position.Z)
wait(5)
end
end)

2 answers

Log in to vote
1
Answered by
commag 228 Moderation Voter
5 years ago

The wait(5) doesn't actually pause your tool from being used. Assuming there are no other issues in the script, this should work.

local usable = true
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key) 
     if key == "z" then
     usable = false
     game.ReplicatedStorage.OpeOpe.Barrier1:Clone().Parent = game.Workspace[player.Name.. "Skills"]
     game.Workspace[player.Name.. "Skills"].Barrier1.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position.X,player.Character.HumanoidRootPart.Position.Y,player.Character.HumanoidRootPart.Position.Z)
wait(5)
usable = true
end
end)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Do this:

local debounce = true

mouse.KeyDown:connect(function(key)
    if debounce == true then 
        debounce = false
        wait(5)
        debounce = true
        return
    end
end)

mouse.KeyDown:connect(function(key)
    if debounce then
        --your script
    end
end)

(I just did something similar but my main function is a little different so idk if it will work)

Answer this question