Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix my animation script - it is broken and I'm unsure of what to do?

Asked by
KingDomas 153
4 years ago

Basically my tool is a wand. Whenever wand is held, animations are played through this script.

--Idle--
local player = game.Players.LocalPlayer
local equipped = false

repeat wait(1) until player.Character

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

local animation2 = Instance.new("Animation")
animation2.Name = "Moving"
animation2.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "6096006842"-- id
animation2.AnimationId = "http://www.roblox.com/asset/?id=" .. "6123318013"-- id

local animtrack = humanoid:LoadAnimation(animation)
local movinganimtrack = humanoid:LoadAnimation(animation2)

script.Parent.Equipped:Connect(function()
    equipped = true
end)

script.Parent.Unequipped:Connect(function()
    equipped = true
end)

while true do
    wait()
    while equipped == true do
        wait()
        if game.Players.LocalPlayer.Character.UpperTorso.Velocity == 0 then
            movinganimtrack:Stop()
            animtrack:Play()
        else
            animtrack:Stop()
            movinganimtrack:Play()
        end
    end
end

When the wand is equipped, if you're not moving, then the first animation (animtrack) plays. If you are moving while the wand is equipped, then the second animation (movinganimtrack) plays. However, I'm getting multiple bugs. Currently the bug I'm getting is it'll set off randomly when I'm holding the wand even if I don't move. On the other hand, when I use the humanoid.Running function, it works but when I unequip the wand it doesn't stop the animation and it breaks. Any help please? Thanks.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try messing with animation priority, https://developer.roblox.com/en-us/api-reference/enum/AnimationPriority

And also you can stop all the running animations when you unequip

Tool.Unequipped:connect(function()
    local c = Player.Character.Humanoid:GetPlayingAnimationTracks()
    for i, v in ipairs(c) do
        if v.Name == "Reload" or v.Name == "Idle" then -- Find animationtracks by name, set them to whatever animationtracks you want to stop
            v:Stop()
        end
    end
end)
Ad

Answer this question