so im making a dash script and the cooldown kicks in after using the dash but u can still spam it one time why is this and how do i fix it
local uis = game:GetService("UserInputService")
local PushForce = 100
local plr = game.Players.LocalPlayer
local character = plr.Character
local tweenservice = game:GetService("TweenService")
local cd = true
local cooldown = 100
uis.InputBegan:Connect(function(key)
if cd == true then
if key.KeyCode == Enum.KeyCode.Q then
print(tostring(cd)..' now')
cd = false
print(tostring(cd)..' after')
character.Archivable = true
local charclone = character:Clone()
charclone:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
charclone.Parent = plr.PlayerGui.ScreenGui.ViewportFrame
for i,v in pairs(charclone:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = true
local goal = {}
goal.Transparency = 1
local tween = tweenservice:Create(v,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0),goal)
tween:Play()
tween.Completed:Connect(function()
tween:Remove()
v:Remove()
end)
end
end
game:GetService("Debris"):AddItem(charclone,1)
local bodyvelocity = Instance.new("BodyVelocity")
bodyvelocity.MaxForce = Vector3.new(1e9,1e9,1e9)
bodyvelocity.Velocity = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").MoveDirection * PushForce
bodyvelocity.Parent = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
game:GetService("Debris"):AddItem(bodyvelocity,0.1)
wait(cooldown)
cd = true
print("set back to "..tostring(cd))
end
end
end)