the player presses and holds F, animation and other things go on in the background. then there is a cooldown. after this cooldown the debounce doesn't do it's job any more. how do i fix this?
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local KeyPressed = false
repeat wait() until Player.Character
c = Player.Character
humanoid = c.Humanoid
local Time = 0
local Debounce = true
--animation codes
local holdAnim = Instance.new("Animation")
holdAnim.AnimationId = "http://roblox.com/asset/?id=4896264874"
local holdTrack = humanoid:LoadAnimation(holdAnim)
local chargeAnim = Instance.new("Animation")
chargeAnim.AnimationId = "http://roblox.com/asset/?id=4896212792"
local chargeTrack = humanoid:LoadAnimation(chargeAnim)
local releaseAnim = Instance.new("Animation")
releaseAnim.AnimationId = "http://roblox.com/asset/?id=4896256143"
local releaseTrack = humanoid:LoadAnimation(releaseAnim)
--function
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if Debounce == false then return end
if input.KeyCode == Enum.KeyCode.F then
KeyPressed = true
Debounce = false
local BG = Instance.new("BodyGyro", c.HumanoidRootPart)
BG.maxTorque = Vector3.new(250000,250000,250000)
BG.CFrame = CFrame.new(c.HumanoidRootPart.Position, mouse.hit.p)
BG.P = 20000
local BP = Instance.new("BodyPosition", c.HumanoidRootPart)
BP.maxForce = Vector3.new(math.huge, math.huge, math.huge)
BP.Position = c.HumanoidRootPart.Position
chargeTrack:Play()
spawn(function()
while KeyPressed == true and Time < 200 do
wait()
BG.CFrame = CFrame.new(c.HumanoidRootPart.Position, mouse.hit.p)
Time = Time + 1
print("Key being held interval: ")
holdTrack:Play()
holdTrack.Looped = true
end
if KeyPressed == false or Time >= 200 then
Time = 0
holdTrack.Looped = false
releaseTrack:Play()
wait(0.5)
BG:Remove()
BP:Remove()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
KeyPressed = false
print("Key has been let go of")
end
wait(5)
Debounce = true
end)
end
end)
