I need some help with my tool script

Okay, so I am trying to do this holding script to play this animation, but it won’t work for some reason, can you guys help me?

This is in a local script IN a tool just to let you know.

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

wait(1)
local Animations = {
	["Idle"] = nil,
	
}


script.Parent.Equipped:Connect(function()
	
   Animations.Idle = player.Character.Humanoid:LoadAnimation(script.Parent.Idle)
		Animations.Idle:Play()
		
end)


script.Parent.Unequipped:Connect(function()
	Animations.Idle = player.Character.Humanoid:LoadAnimation(script.Parent.Idle)
	Animations.Idle:Stop()
end)


I have no idea why it is not working, the equip animation is working but not the unequipping

can you please help?

Because you’re creating another animationTrack when you unequip and it stops that new track instead of the one that’s currently playing. I think you only need the Animations.Idle:Stop() in the unequipped event, and probably something to set Animation.Idle to nil

1 Like

So something like this?

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

wait(1)
local Animations = {
	["Idle"] = nil,
	
}


script.Parent.Equipped:Connect(function()
	
   Animations.Idle = player.Character.Humanoid:LoadAnimation(script.Parent.Idle)
		Animations.Idle:Play()
		
end)


script.Parent.Unequipped:Connect(function()
	Animations.Idle:Stop()
	Animations.Idle = nil
end)

script.Parent.Activated:Connect(function()
	
	
end)

Why setting it to nil now ? You could try moving the array to the equipped function so it’ll load only when equipped

oh yeah… but then how could I stop the animation if the script doesn’t know what animation to stop?

Wait, your assinging a value to the LoadAnimation function, that return an animation and not a string or something

Try something like this :

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

local idle = nil;

idle = player.Character.Humanoid:LoadAnimation(script.Parent.Idle)

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

script.Parent.Unequipped:Connect(function()
	idle:Stop()
end)

it pops up with this error

Players.Inferno9878.Backpack.AssaultRifle2.HoldAnimationScript:6: attempt to index nil with ‘Humanoid’

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

repeat wait() until player.Character and player.Character:FindFirstChild("Humanoid")

local Animations = {
	["Idle"] = player.Character.Humanoid:LoadAnimation(script.Parent.Idle),
}

script.Parent.Equipped:Connect(function()
    Animations.Idle:Play()
end)


script.Parent.Unequipped:Connect(function()
	Animations.Idle:Stop()
end)

script.Parent.Activated:Connect(function()
    --
end)

try this

Still doesn’t work, I am using r6 for it, could that be the problem?

if your animation was made using an r6 rig and you’re character is an r6 rig, it should work fine

could you possibly show a video of the animation in the animation editor?

Try this?

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

local Animations = {
	["Idle"] = nil,
}

script.Parent.Equipped:Connect(function()
	if not Animations.Idle then
		Animations.Idle = player.Character.Humanoid.Animator:LoadAnimation(script.Parent.Idle)
	end
    Animations.Idle:Play()
end)

script.Parent.Unequipped:Connect(function()
	Animations.Idle:Stop()
end)

script.Parent.Activated:Connect(function()
    --Code
end)
1 Like

ok. I don’t know if I can do a picture, it errors but I’ll try and see

show a picture of the error in the output

oh, you mean the one that XRH Tech sent me?

because your script dosen’t show any errors for some reason

seems like it’s a problem with the animation

ok, I’ll take a photo and send it

for some reason when I try to upload the video or picture, it errors and it says that there was an error, please try again