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

my hold animation wont continue playing How do i fix this?

Asked by
ym5a 52
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 loadedAnim
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")
        loadedAnim = Animator:LoadAnimation(holdAnim)
        loadedAnim.Looped = true
        loadedAnim.Priority = Enum.AnimationPriority.Action
        loadedAnim:Play()
    end
end)
tool.Unequipped:Connect(function()
    loadedAnim:Stop()
end)

This is a serverScript If nobody can fix this I will have to resort to CFraming, which I REALLY do not want to do. https://www.roblox.com/library/7467408348/betterHold-hoepfully --This is the one im using, Its Incredibly long and looped Original one -- https://www.roblox.com/library/7466688023/hold -- Incredibly short , not looped (well I dont thhtink it is)

---What happens, https://gyazo.com/0acbc706d69860326341bb4a226beea8 when you ReEquipd it plays but then stops after a bit (assuming you are Idle)

1 answer

Log in to vote
0
Answered by
ym5a 52
3 years ago

I fixed it, I had to load and play the animation on the Server AND client so it could replicate, How I did it: I used a RemoteFunction once it is equipped it calls the function and sends the Animation to the server the server then makes an Animator and takes the Passed Animation and loads and playss it there, then it returns the animator which the Client uses to play the animations

--LocalScript
local plr = game.Players.LocalPlayer
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent
local loadedAnim
local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
    local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
    if humanoid then
        local animater = script.Parent.RemoteFunction:InvokeServer(holdAnim)
        loadedAnim = animater:LoadAnimation(holdAnim)
        loadedAnim.Looped = true
        loadedAnim.Priority = Enum.AnimationPriority.Action
        loadedAnim:Play()
    end
end)
tool.Unequipped:Connect(function()
    loadedAnim:Stop()
end)
--ServerScript
script.Parent.RemoteFunction.OnServerInvoke = function(plr,holdanm)
    local Animater = Instance.new("Animator")
    Animater.Parent = plr.Character:WaitForChild("Humanoid")
    local l = Animater:LoadAnimation(holdanm)
    l.Looped = true
    l.Priority = Enum.AnimationPriority.Action
    l:Play()
    return Animater
end
Ad

Answer this question