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

sword animation plays after being unequipped but not when equipped how do i fix?

Asked by 5 years ago
   local bussy = false
local lastSlasj = tick()


    local player = game.Players.LocalPlayer
    local  char = player.Character

     wait(1)

    local aims = { ["idle"] = nil
    }



script.Parent.Equipped:Connect(function()
    local  char = player.Character
    aims.idle = Enum.AnimationPriority.Idle
    aims.idle = char.Humanoid:LoadAnimation(script.Parent.idle)


aims.idle:Play()








end)
0
i have 2 chars because it kept saying character is a nill value   also i tryed put the Priority to action dose the same thing  helleric -3 — 5y

1 answer

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

When you call the AnimationPlayer (anim.idle) you need to have this predefined, because every time you equip the tool, the animation will be loaded again and you won't be able to stop it with another function except the .Equipped event you first created it in.

It is also probably better to name your variable something without a period in its name, since the period denotes the hierarchy of the variable you are going to call.

You also defined "aims.idle" twice, so the second definition will override the first. Since the first definition is a property (Priority), you can define this after setting the variable.

LocalScript

local bussy = false
local lastSlasj = tick()

local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name)

wait(1)
local aims = {["idle"] = nil}

local animPlayer = char.Humanoid:LoadAnimation(script.Parent.idle)
animPlayer.Priority = Enum.AnimationPriority.Idle

script.Parent.Equipped:Connect(function()
    animPlayer:Play()
end)

script.Parent.Unequipped:Connect(function()
    animPlayer:Stop()
end)
Ad

Answer this question