#i made a tool script when press Q will CD 60sec but if rehold the tool the CD will reset how to fix

4 messages · Page 1 of 1 (latest)

charred rivet
#

this is a tool script when press Q will CD 60sec but if rehold the tool the CD will reset please help fix this bug
tool inside:
SkillScript(localscript)
SkillScript inside Keybind(localscript)
Keybind inside have a RemoteEvent name called Fire
inside the RemoteEvent script:
Effect
Main

SkillScript:
local Tool = script.Parent

Tool.Equipped:Connect(function()
script.Keybind.Disabled = false
end)

Tool.Unequipped:Connect(function()
script.Keybind.Disabled = true
end)
Keybind:
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Debounce = true
local Player = game.Players.LocalPlayer
local Animation = script.Parent.Animation
local cooldown = 60 -- CD时间,单位为秒

UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Q and Debounce == true then
Debounce = false
local Track1 = Player.Character.Humanoid:LoadAnimation(Animation)
Track1:Play()
script.Fire:FireServer(plr)
wait(cooldown)
Debounce = true
end
end)

#

Effect:
script.Parent.OnServerEvent:Connect(function(plr)
local Effect = game.ReplicatedStorage.Asset.Effect:Clone()
Effect.Parent = workspace
Effect.CanCollide = false
Effect.Anchored = true
Effect.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-8) * CFrame.fromEulerAnglesXYZ(0,0,0)
wait(0.2)
for i = 1,18 do
wait(0.01)
Effect.Size = Effect.Size + Vector3.new(2,2,2)
Effect.Transparency = Effect.Transparency + 0.025
end
Effect:Destroy()
wait(0.2)
end)

#

Main:
script.Parent.OnServerEvent:Connect(function(plr)
wait(0.2)
local Projectile = game.ReplicatedStorage.Asset.Slash:Clone()
Projectile.Parent = workspace
Projectile.CanCollide = false
Projectile.Anchored = false
Projectile.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,2,-1.5) * CFrame.fromEulerAnglesXYZ(0,0,-5)
Projectile.Start:Play()
Projectile.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
local HitEffect = game.ReplicatedStorage.Asset.Hit:Clone()
HitEffect.Parent = workspace
HitEffect.CFrame = hit.CFrame
HitEffect.CanCollide = false
HitEffect.Anchored = true
HitEffect.Explosion11:Play()
Projectile:Destroy()
hit.Parent.Humanoid:TakeDamage(40)
for i = 1,18 do
wait(.05)
HitEffect.Size = HitEffect.Size + Vector3.new(2,2,2)
HitEffect.Transparency = HitEffect.Transparency + 0.1
end
HitEffect:Destroy()
end
end)
local BV =
Instance.new("BodyVelocity",Projectile)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 100
wait(2)
Projectile.Lightning:Emit(8)
Projectile.Lightning1:Emit(8)
Projectile.SPe:Emit(10)
Projectile.SPe1:Emit(10)
Projectile.Star:Emit(5)
wait(.01)
Projectile:Destroy()
end)
i want to fix tool rehold cd reset bug

#

i think is Keybind(localscript) problem