You can stop it if you click on a button but i’d also like if people stopped dancing if they move
I have tried different animation priorities also in the script it is changeable but if you stop moving you see the character doing weird like he is doing the first millisecond of the animation
This is the script
local anims = script:WaitForChild("Animations"):GetChildren()
local templateBtn = script:WaitForChild("AnimButton")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local currentAnim = nil
for i, anim in pairs(anims) do
local loadedAnim = humanoid:LoadAnimation(anim)
loadedAnim.Looped = true
loadedAnim.Priority = Enum.AnimationPriority.Action
local templateClone = templateBtn:Clone()
templateClone.Text = anim.Name
templateClone.Parent = script.Parent.AnimationsScroll
templateClone.MouseButton1Click:Connect(function()
if currentAnim ~= loadedAnim then
if currentAnim then currentAnim:Stop() end
currentAnim = loadedAnim
currentAnim:Play()
elseif currentAnim == loadedAnim then
currentAnim:Stop()
currentAnim = nil
end
end)
end
humanoid.Running:Connect(function(speed)
if speed >= 0.1 then
--code
end
end)
to check when the player starts walking.
After that, :Stop the currentAnimAnimationTrack:
humanoid.Running:Connect(function(speed)
if speed >= 0.1 then
if currentAnim then
currentAnim:Stop()
end
end
end)
Putting that all together:
local anims = script:WaitForChild("Animations"):GetChildren()
local templateBtn = script:WaitForChild("AnimButton")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local currentAnim = nil
local function setUpAnimation(anim)
local loadedAnim = humanoid:LoadAnimation(anim)
loadedAnim.Looped = true --Warning: might not replicate
loadedAnim.Priority = Enum.AnimationPriority.Action
local templateClone = templateBtn:Clone()
templateClone.Text = anim.Name
templateClone.Parent = script.Parent.AnimationsScroll
templateClone.MouseButton1Click:Connect(function()
if currentAnim ~= loadedAnim then
if currentAnim then currentAnim:Stop() end
currentAnim = loadedAnim
currentAnim:Play()
elseif currentAnim == loadedAnim then
currentAnim:Stop()
currentAnim = nil
end
end)
end
humanoid.Running:Connect(function(speed)
if speed >= 0.1 then
if currentAnim then
currentAnim:Stop()
end
end
end)
for i, anim in pairs(anims) do
setUpAnimation(anim)
end
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if humanoid.WalkSpeed > 0 then
animationTrack:Stop()
else
animationTrack:Play()
end
end)