When the tool is equipped the character glitches

this is my script of the tool when equipped

local Player = game.Players.LocalPlayer

repeat wait() until Player.Character -- just waits till the character spawns to get the animations

local Character = Player.Character 

local Humanoid = Character:FindFirstChild("Humanoid")

local Animation = Humanoid:LoadAnimation(script.Animation)

local IdleTrack
local EquipUnequipTrack

local Idle = Instance.new("Animation")

local EquipUnequip = Instance.new("Animation")


Idle.AnimationId = "http://www.roblox.com/Asset?ID=11890425986" 

EquipUnequip.AnimationId = "http://www.roblox.com/Asset?ID=11906096433" 


tool = script.Parent




tool.Equipped:Connect(function()
	
	script.Parent.Show:FireServer()
	
	IdleTrack = script.Parent.Parent.Humanoid:LoadAnimation(Idle)
	EquipUnequipTrack = script.Parent.Parent.Humanoid:LoadAnimation(EquipUnequip)
	game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = 'rbxassetid://11901386770'
	
	EquipUnequipTrack:Play()
wait(0.05)	
	IdleTrack:Play()
	
end)

tool.Unequipped:Connect(function()
	
	script.Parent.Hide:FireServer()
	
	IdleTrack:Stop()
	EquipUnequipTrack:Play()
	
	game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = 'rbxassetid://180426354' --default id
end)

iam not sure if theres any issues with the script this is what happens when the tool is equipped

Video ← video of the glitch

try testing it by joining the place from roblox, not the studio.

1 Like

Maybe this is happening because you are calling Humanoid:LoadAnimation() everytime Tool.Equipped fires, and Humanoid:LoadAnimation() is deprecated. You should use the Humanoid’s Animator and call Animator:LoadAnimation() instead; create an Animator using Instance.new() if the Humanoid doesn’t have one.

Also, instead of loading the animation everytime the Tool.Equipped event fires, do you think you could just store the tracks outside of the event? For example:

local character = player.Character
local animator = character.Humanoid.Animator

local idleTrack, equipTrack

local function createTrack(id: string)
    local animation = Instance.new("Animation")
    animation .AnimationId = id

    return animator:LoadAnimation(animation)
end

idleTrack = createTrack("http://www.roblox.com/Asset?ID=11890425986")
equipTrack = createTrack("http://www.roblox.com/Asset?ID=11906096433")

tool.Equipped:Connect(function()
    equipTrack:Play()
    task.wait(0.05)
    idleTrack:Play()
end)

tool.Unequipped:Connect(function()
    equipTrack:Stop()
    idleTrack:Stop()
end)
1 Like

i think that will work i will try it

sorry for the late response tho

but the animations arent working the default animation is playing

and there is an animator in the humanoid

it did work thank you for the help its stupid how it works in the place but not in roblox studio

1 Like

thank you for the help turns out its just glitching in the studio when i tested it in roblox player it worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.