Animation Track repeating when input is triggered once?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want this animation Track to only play once
  2. What is the issue? Include screenshots / videos if possible!
    As i stated its repeating when the input is processed only once not sure why this is occurring
local rs = game:GetService("RunService")
local remote = game.ReplicatedStorage.RemotesFolder.Movement
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")

local PlrMovementMod = require(game.ReplicatedStorage.Modules.PlayerMovement)
local chargeTimer = 0
local MaxInterval = 0.6

local inputHandler = false


local function stopAllAnimations()
	for _, track in pairs(char.Humanoid.Animator:GetPlayingAnimationTracks()) do
		track:Stop()
	end
end

local function UpdateChargingJump(value)
	char:SetAttribute("ChargingJump", value)
end

local function increaseChargeValue()
	local index = char:GetAttribute("ChargeValue") or 0
	char:SetAttribute("ChargeValue", math.min(index + 5, 100))
end

local function chargeValueCleanUp()
	char:SetAttribute("ChargingValue", 0)
end


rs.RenderStepped:Connect(function(deltaTime)
	PlrMovementMod.Movement(player, char, humanoid, animator)
	for _, Track in pairs(animator:GetPlayingAnimationTracks()) do
	end
	
end)
uis.InputBegan:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Space and not inputHandler then
		inputHandler = true  
		print("input began")
		char:SetAttribute("ChargingJump", true)
		remote:FireServer("Charging")
		local track = animator:LoadAnimation(game.ReplicatedStorage.Animations["Charging Jump"])
		track:Play()
		track.Stopped:Connect(function()
			print("track stopped")
			inputHandler = false 
		end)
	end
end)

uis.InputEnded:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Space then
		inputHandler = false 
		char:SetAttribute("ChargingJump", false)
		remote:FireServer("NotCharging")
		char:SetAttribute("ChargeValue", 0)
		stopAllAnimations()
	end
end) 

https://gyazo.com/3f56fb89416f6948940e5911985adb5c
This is my local script where im handling the animation and input

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking on forums for a case similar couldn’t find a topic similar besides that im not sure what to try!
1 Like

Can you send the PlayerMovement module, were you print “ChargingJump is true” ?

Sure thing this is the module to make sure the loop wasnt causing this i removed it and tested it and came with the same results

local PlrMovementMod = {}

local rs = game:GetService("RunService")
local maxTimeInterval = 0.65
local lastIncrementTime = 0  

-- TODO: CHARGING JUMP PHASE INTO LOOPED CHARGING PHASE 
function PlrMovementMod.Movement(player, character, humanoid, animator)
	local ChargeValue = character:GetAttribute("ChargingValue")
	local ChargingJump = character:GetAttribute("ChargingJump")
	local Thrown = character:GetAttribute("Thrown")

	if ChargingJump then -- Holding Space
		local currentTime = os.clock()

		if currentTime - lastIncrementTime >= maxTimeInterval then
			local chargingIndex = character:GetAttribute("ChargingValue") or 0
			character:SetAttribute("ChargingValue", math.min(chargingIndex + 5, 100))
			print("ChargingJump is true")
			lastIncrementTime = currentTime  -- Update last increment time
		end
	else
		character:SetAttribute("ChargingValue", 0) 
	end
end

return PlrMovementMod

Is the animation is in repeat mode ? Because the uis.InputBegan:Connect(function(input, isProcessed) function never prints “track stopped”, maybe it’s for that reason.

Ah, my mistake :sweat_smile: looping was toggled for the animation

1 Like