Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

i want Tool to countdown for 5 seconds?

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

✓ Accepted answer

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.