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?

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

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.

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

Do this:

01local debounce = true
02 
03mouse.KeyDown:connect(function(key)
04    if debounce == true then
05        debounce = false
06        wait(5)
07        debounce = true
08        return
09    end
10end)
11 
12mouse.KeyDown:connect(function(key)
13    if debounce then
14        --your script
15    end
16end)

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

Answer this question