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)
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!