I m trying to make an action when a specific key is hold down and when the key is released the action stops. Everything work fine, The problem is when I test it and another key than the one specify is released the action stop. Like when the Key is hold down the action play but when you move and then stop moving the action stop while the specified key is always pressed down.
Can someone help me I cant figure it out, here is the script
local Player = game.Players.LocalPlayer
local Character = Player.Character or script.Parent
local Humanoid = Character.Humanoid
local UserInputService = game:GetService("UserInputService")
local CoolDown = 5
local AnimationId = 'rbxassetid://2578167315'
local Debounce = true
local Key = 'Q'
game:GetService('UserInputService').InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[Key] and Debounce == true then
Debounce = false
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId
local LoadAnimation = Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
game.ReplicatedStorage.Events.Barrier:FireServer(CFrame.new(0,6,-5))
game:GetService("UserInputService").InputEnded:connect(function(input,IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[Key] and Debounce == false then
game.ReplicatedStorage.Events.BarrierEnd:FireServer()
Debounce = true
end
end)
end
end)
