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

Animation wont keep playing on Equip how fix ?

Asked by
ym5a 52
3 years ago
Edited 3 years ago
local plr = game.Players.LocalPlayer
local event = script.Parent.RemoteEvent
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent

local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
    local animator 
    wait(0.2)
    local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
    print(humanoid)
    print(humanoid.Parent)
    if humanoid ~= nil then
        animator = Instance.new("Animator",humanoid)
        animator.Parent = humanoid
    end
    holdAnim.Parent = humanoid
    local Animater = humanoid:WaitForChild("Animator")
    local loadedAnim = Animater:LoadAnimation(holdAnim)
    loadedAnim:Play()

    print("H")
end)

This is on a Server Script . What happens: https://gyazo.com/178fd7dc5d1027c5bcb309228055e64e Please help me bustaronies ! There are NO errors in output

Also I just want to thank this Site because I probably wouldnt be coding if it didnt push me to start, thanks to everybody who responed to all my threads, I greatly appreciate you. Anybody can learn LUA

1 answer

Log in to vote
0
Answered by 3 years ago

Problem

I'm pretty sure all you need to do is loop the animation and set the animation priority to Action(Max priority). Setting it to the Action priority will override all animations that have an animation priority below the Action priority.

You don't need to create the Animator, it's already there, but you can't see it.

Recommendations

  1. You should avoid using wait(n) Waiting for events to be fired is a better solution than wait(n) for example, RunService.Heartbeat:Wait() is better. Using wait(n) or wait() can decrease the performance of your game. If you want more information on avoiding waits, you can look here.

  2. It's a bad practice to create a new Instance and instantly parent it. You should change all the property first, then the last thing you do is parent it. Doing this can increase performance.

Fixed code

local plr = game.Players.LocalPlayer
local event = script.Parent.RemoteEvent
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent

local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
    local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
    if humanoid then
       local Animator = humanoid:WaitForChild("Animator")
       local loadedAnim = Animator:LoadAnimation(holdAnim)
       loadedAnim.Looped = true
       loadedAnim.Priority = Enum.AnimationPriority.Action
       loadedAnim:Play()
   end
end)

Hopefully, this should work because I wrote the code here and not in Roblox Studio.

0
Ok Ill try it out ym5a 52 — 3y
0
It did not work, by the animation is incredibly long and Looped when I made it ym5a 52 — 3y
0
@ym5a Are there any errors in the output? MarkedTomato 810 — 3y
0
https://gyazo.com/3066095fdc2020e0ffa4a7f7cddb0741 This is what happens, I also added when it is unequipped it stops playing the Animation ym5a 52 — 3y
0
@MarkedTomate No. ym5a 52 — 3y
Ad

Answer this question