Animation Track Wont Stop

I’ve asked this a few times but i have this script, everything works, (including the animation) but it won’t stop when i tell it to.

–Here’s The Script

local UIS = game:GetService("UserInputService")

local weld = Instance.new("Weld")
local swinging = false

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://18263356301"

local function onSwingEvent(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")
	

	local animTrack = animator:LoadAnimation(animation)
	animTrack:Stop()

	if not swinging then
		char.PrimaryPart.CFrame = game.Workspace.Cylinder.CFrame * CFrame.new(0, 10, 0)
		weld.Part0 = game.Workspace.Cylinder
		weld.Part1 = char.PrimaryPart
		weld.Parent = char
		weld.C1 = CFrame.new(0, 2, 0)
		animTrack:Play()
		swinging = true
	else
		weld.Parent = game.ReplicatedStorage
		task.wait(0.1)
		animTrack:Stop()
		print("check")
		swinging = false
	end
end

game.ReplicatedStorage.SwingEvent.OnServerEvent:Connect(onSwingEvent)
local UIS = game:GetService("UserInputService")
local weld = Instance.new("Weld")
local swinging = false

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://18263356301"

local function onSwingEvent(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")
	local animTrack = animator:LoadAnimation(animation)

	if not swinging then
		char.PrimaryPart.CFrame = game.Workspace.Cylinder.CFrame * CFrame.new(0, 10, 0)
		weld.Part0 = game.Workspace.Cylinder
		weld.Part1 = char.PrimaryPart
		weld.Parent = char
		weld.C1 = CFrame.new(0, 2, 0)
		animTrack:Play()
		swinging = true
	else
		weld.Parent = nil
		animTrack:Stop()
		swinging = false
	end
end

game.ReplicatedStorage.SwingEvent.OnServerEvent:Connect(onSwingEvent)

Make sure some other script isn’t interacting with the animation also.

I dont have any other scripts interfering with the animation but it still won’t work

Drop a print something after that else to see if it’s getting to that point.

i have, it does print. but it just won’t work for some reason

Try a different animation you know works completely.

local UIS = game:GetService("UserInputService")

local weld = Instance.new("Weld")
local swinging = false

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://18263356301"

local animTrack -- Declare animTrack outside the function

local function onSwingEvent(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")
    local animator = hum:WaitForChild("Animator")
    
    -- Load the animation only if it hasn't been loaded yet
    if not animTrack then
        animTrack = animator:LoadAnimation(animation)
    end

    if not swinging then
        char.PrimaryPart.CFrame = game.Workspace.Cylinder.CFrame * CFrame.new(0, 10, 0)
        weld.Part0 = game.Workspace.Cylinder
        weld.Part1 = char.PrimaryPart
        weld.Parent = char
        weld.C1 = CFrame.new(0, 2, 0)
        animTrack:Play()
        swinging = true
    else
        animTrack:Stop()
        weld.Parent = game.ReplicatedStorage
        task.wait(0.1)
        swinging = false
    end
end

game.ReplicatedStorage.SwingEvent.OnServerEvent:Connect(onSwingEvent)

that script works perfectly, thanks!

1 Like

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