Animation doesn't stop playing

Hi! I’m making a script that plays an animation whenever an ability is used. I have no idea on why it doesn’t stop playing. I’ve tried using Humanoid:WaitForChild(Animator), but that doesn’t work. If it worked then I wouldn’t be able to start the animation, either.

Script:

game.ReplicatedStorage.AbilityUse.OnServerEvent:Connect(function(plr)
	local HideTable = plr.PlayerGui.Animations:WaitForChild("HideTable")
	local TableProtect = game.Workspace.TableProtect:Clone()
	plr.Character.Humanoid:LoadAnimation(HideTable):Play()
	plr.Character.Humanoid.WalkSpeed = 0
	plr.Character.Humanoid.JumpHeight = 0
	wait(0.5)
	TableProtect.Parent = game.Workspace
	TableProtect.PrimaryPart.CFrame = plr.Character.HumanoidRootPart.CFrame
	for i,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("Part") then
			v.CanTouch = false

		end
	end
	wait(4)
	plr.Character.Humanoid:LoadAnimation(HideTable):Stop()
	print(plr)
	print(HideTable)
	plr.Character.Humanoid.WalkSpeed = 26
	plr.Character.Humanoid.JumpHeight = 7.2
	for i,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("Part") then
			v.CanTouch = true
		end
	end
	TableProtect:Destroy()
end)

Any help appreciated!

Dont load it twice put it in a single variable

local anim = plr.Character.Humanoid:LoadAnimation(Anim)
anim:Play()
--do whatever
anim:Stop()

Loading it twice is making two animations and not the one you played.

What RedDeath said is exactly why it’s not working you’re loading the animation and playing it but on the line where you use :Stop() you’re actually loading an entirely different animation so replace the script with this

game.ReplicatedStorage.AbilityUse.OnServerEvent:Connect(function(plr)
	local HideTable = plr.PlayerGui.Animations:WaitForChild("HideTable")
	local TableProtect = game.Workspace.TableProtect:Clone()
	local HideTableAnim = plr.Character.Humanoid:LoadAnimation(HideTable)
    HideTableAnim:Play()
	plr.Character.Humanoid.WalkSpeed = 0
	plr.Character.Humanoid.JumpHeight = 0
	wait(0.5)
	TableProtect.Parent = game.Workspace
	TableProtect.PrimaryPart.CFrame = plr.Character.HumanoidRootPart.CFrame
	for i,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("Part") then
			v.CanTouch = false

		end
	end
	wait(4)
	HideTableAnim:Stop()
	print(plr)
	print(HideTable)
	plr.Character.Humanoid.WalkSpeed = 26
	plr.Character.Humanoid.JumpHeight = 7.2
	for i,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("Part") then
			v.CanTouch = true
		end
	end
	TableProtect:Destroy()
end)

Thanks for the help. I don’t really know who to give the solution to. RedDeath replied first but Fimutsu made it more clear. Well I still thank you very much for the help!

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