Animation Isn't Stopping

Hey, I’m trying to make an animation similar to what a Dragon Ball Ki Charge is. My only problem is that whenever I release the key bind that starts the animation, it doesn’t stop.

I’ve checked the play-test logs and Roblox Studio logs, but nothing appears. Could anyone help me figure out on what’s going on? I have 2 scripts that make it so it appears on both client & server.

Here’s the LocalScript I made called ChargingKi.

local UIS = game:GetService("UserInputService")
local RepStorage = game.ReplicatedStorage
local Remote = RepStorage.KiChange

UIS.InputBegan:Connect(function(input) -- once the script detects an input, it will run
	if input.KeyCode == Enum.KeyCode.C then
		Remote:FireServer("isCharging")
	end
end)

UIS.InputEnded:Connect(function(input) -- similar to "InputBegan", but checks when the input has ended
	if input.KeyCode == Enum.KeyCode.C then
		Remote:FireServer("isNotCharging")
	end
end)

Here’s the normal script I made called KiChargeDetector.

local rs = game.ReplicatedStorage
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://135685597117166"

rs.KiChange.OnServerEvent:Connect(function(player, value) -- when the server receive a value, it will run the code below
	local char = player.Character
	local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
	if value == "isCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 0
		char:WaitForChild("Humanoid").JumpPower = 0
		char:WaitForChild("HumanoidRootPart").Anchored = true
		track:Play()
	end
	if value == "isNotCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 16
		char:WaitForChild("Humanoid").JumpPower = 50
		char:WaitForChild("HumanoidRootPart").Anchored = false
		track:Stop()
	end
end)
1 Like

Forgot to add this into the main post, but the animation is meant to loop.

Did you try turning the animation’s looped property to false before you ended it? @TotallyNotSprite00

local UIS = game:GetService(“UserInputService”)
local RepStorage = game.ReplicatedStorage
local Remote = RepStorage.KiChange

UIS.InputBegan:Connect(function(input) – once the script detects an input, it will run
if input.KeyCode == Enum.KeyCode.C then
Remote:FireServer(“isCharging”)
end

UIS.InputEnded:Connect(function(input2) – similar to “InputBegan”, but checks when the input has ended
if input2.KeyCode == Enum.KeyCode.C then
Remote:FireServer(“isNotCharging”)
end

end)

end)

try this

As far as I know, I never knew you could make a loop property become false.

Change this to this:

local player_tracks = {}
rs.KiChange.OnServerEvent:Connect(function(player, value) -- when the server receive a value, it will run the code below
    local char = player.Character
    if not(player_tracks[player]) then -- First time adding an AnimationTrack
        player_tracks[player] = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
    end
	if value == "isCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 0
		char:WaitForChild("Humanoid").JumpPower = 0
		char:WaitForChild("HumanoidRootPart").Anchored = true
		player_tracks[player]:Play()
	end
	if value == "isNotCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 16
		char:WaitForChild("Humanoid").JumpPower = 50
		char:WaitForChild("HumanoidRootPart").Anchored = false
		player_tracks[player]:Stop()
	end
end)

I’m assuming here that every time the OnServerEvent is received, it will create a new charging animation for the player, meaning you’re only cancelling the newly created one when value == "isNotCharging", and the animation from value == "isCharging" is still playing.
Remember when using animationtracks, you only need to load in the animation once, and then make it :Play() and :Stop(). Hence this is why storing the animation track for each player in a dictionnary player_tracks allows to easily fetch it and play/stop it.

Trying Changing it to this, Also Delete The HumanoidRootPart Anchored Part Since You’re Having the player Speed and Height to 0/ Making The Player Not available To Move

rs.KiChange.OnServerEvent:Connect(function(player, value) 
	local char = player.Character
	local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
	if value == "isCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 0
		char:WaitForChild("Humanoid").JumpPower = 0
		track:Play()
	elseif value == "isNotCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 16
		char:WaitForChild("Humanoid").JumpPower = 50
		track:Stop()
		end
end)

This does fix the issue, but now there’s a new problem… after the keybind is lifted, the animation still plays out until the end. I can’t be sure if this is the script or the animation.

Can u record it so i can see

Yup! Just give me a second so I can send it over

Did you try my code ? There’s another way to stop animations, weirdly enough this has worked for them.

Yes I’ve tried your code, but got the same result. I’ll try the link you sent me.
Edit 1: The link that should’ve helped, didn’t work.

Okay Tried Putting this then

rs.KiChange.OnServerEvent:Connect(function(player, value) 
	local char = player.Character
	local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
	if value == "isCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 0
		char:WaitForChild("Humanoid").JumpPower = 0
		track:Play()
	elseif value == "isNotCharging" then
		char:WaitForChild("Humanoid").WalkSpeed = 16
		char:WaitForChild("Humanoid").JumpPower = 50
		
        -----------Stops Current Animation
		for i,v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
			v:Stop()
		end

		end
end)

WOW, that is actually smooth. This also worked flawlessly.
I also thank everyone who helped me with this animation bug.

2 Likes

lol sorry im not good at animations :sob:

It’s okay not to be good at something, but at least you tried your best!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.