I'm making a charging animation where the player recharges their energy. However, after a certain amount of time of holding, the animation stops.

-- Client

local UIS = game:GetService("UserInputService")
local debounce = false

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local database = player:WaitForChild("Database")
local magicType = database.Magic

local charge = Instance.new("Animation")
charge.AnimationId = "rbxassetid://4738576556"
local chargeAnim = hum:LoadAnimation(charge)

local isHolding = false

chargeAnim.KeyframeReached:Connect(function(keyframe)
	if keyframe == "Pause" then
		chargeAnim:AdjustSpeed(0)
		chargeAnim.TimePosition = chargeAnim.Length
	end
end)

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift and not debounce and not isHolding then
		debounce = true
		isHolding = true
		
		chargeAnim:Play()
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		wait()
		debounce = false
	end
end)

UIS.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift and not debounce and isHolding then
		debounce = true
		isHolding = false
		
		chargeAnim:Stop()
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		
		wait(0.5)
		debounce = false
	end
end)

I've even tried freezing the animation at a point, but it still stops the animation.

2 comments

0

I don't get why this doesn't work...

0

neither do i..