When the player jumps it stops the animation [SOLVED]

how do i make this when the player jumps the animation will stop
heres the code

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

if script.Parent.slots and script.Parent.slots:IsA("Frame") then
	local children = script.Parent.slots:GetChildren()
	for _, child in pairs(children) do
		if child:IsA("Frame") then
			local buttonchildren = child:GetChildren()
			for _, button in pairs(buttonchildren) do
				if button:IsA("TextButton") then
					button.MouseButton1Click:Connect(function()
						humanoid:LoadAnimation(button.Parent.config.animation):Play()
						humanoid.WalkSpeed = 3
						button.Parent.music:Play()						
					end)
					humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
						if humanoid.Jump == true then
							humanoid.WalkSpeed = 16
							button.Parent.config/animation:Stop()
							button.Parent.config.music:Stop()
						end
					end)
				end
			end
		end
	end
end

and this is a local script

1 Like

Have the animation as a variable so you can access it when you want.
then just do this when you want to stop it:

-- its one of these
animation:Stop()
animation:Pause()

it doesnt let me stop it

could you resend the script with modification you made please?

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

if script.Parent.slots and script.Parent.slots:IsA("Frame") then
	local children = script.Parent.slots:GetChildren()
	for _, child in pairs(children) do
		if child:IsA("Frame") then
			local buttonchildren = child:GetChildren()
			for _, button in pairs(buttonchildren) do
				if button:IsA("TextButton") then
					local animation = button.Parent.config.animation
					button.MouseButton1Click:Connect(function()
						humanoid:LoadAnimation(animation):Play()
						humanoid.WalkSpeed = 3
						button.Parent.music:Play()						
					end)
					humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
						if humanoid.Jump == true then
							humanoid.WalkSpeed = 16
							animation:Stop()
						end
					end)
				end
			end
		end
	end
end






I believe you have to stop the track, not the animation itself.

Indeed what @ProtectpocketAgain said, you need to stop the animation that you loaded:

That being this, turn into a variable so you can play it and stop it when you need to

1 Like

like this

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

if script.Parent.slots and script.Parent.slots:IsA("Frame") then
	local children = script.Parent.slots:GetChildren()
	for _, child in pairs(children) do
		if child:IsA("Frame") then
			local buttonchildren = child:GetChildren()
			for _, button in pairs(buttonchildren) do
				if button:IsA("TextButton") then
					local animation = button.Parent.config.animation
					button.MouseButton1Click:Connect(function()
						local animationTrack = humanoid:LoadAnimation(animation)
                        animationTrack:Play()
						humanoid.WalkSpeed = 3
						button.Parent.music:Play()						
					end)
					humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
						if humanoid.Jump == true then
							humanoid.WalkSpeed = 16
							animationTrack:Stop()
						end
					end)
				end
			end
		end
	end
end
2 Likes

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