Loading an animation in a humanoid

You are trying to find the humanoid in the player instead of the character

1 Like

-- code for animations and stuff
local plr = -- YourPlayer Here
function unEquipped()
	
	local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
	drink:Stop()
	local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
	equip:Stop()
end

script.Parent.Unequipped:Connect(unEquipped)
1 Like

Ah, I will try to fix it.

Edit: it didn’t work, but the bug is removed.

1 Like

cuz you’re not playing the animation, add :Play()

1 Like

Why would I have to play the animation when I want it to stop?

1 Like

oh yeah you want it to stop, can you show us your updated code?

1 Like
local plr = script.Parent.Parent.Parent

function unEquipped()
	local plr = script.Parent.Parent.Parent
	
	local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
	drink:Stop()
	
	local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
	equip:Stop()
end

script.Parent.Unequipped:Connect(unEquipped)
1 Like

Might be because you’re loading a new animation (despite it being the same animation) onto the humanoid. Take the original saved animation and use :Stop() on that instead

1 Like

ru sure that script.Parent.Parent.Parent is the player?
if the localscript is located in StarterPlayerScripts the player will be script.Parent

1 Like

i believe he’s playing it OnEquipped()

1 Like

It is a script inside of a Bloxy Cola.

Summary

This text will be hidden

1 Like

then the character will be script.Parent.Parent

function unEquipped()
	local char = script.Parent.Parent
	
	local drink = char:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
	drink:Stop()
	
	local equip = char:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
	equip:Stop()
end

script.Parent.Unequipped:Connect(unEquipped)
1 Like

So then what should I do?

Summary

This text will be hidden

1 Like

Load the animation outside of any equipped & unequipped events, then when the tool is equipped do :Play() and when it is unequipped do :Stop()

1 Like

I have an idea, instead of putting it in the function, I will put It as a variable

1 Like

It completely breaks the script and the animation never even ends up playing. I will try to add .character

1 Like

nvm, it doesn’t make sense since you’re loading the anim & stopping it

1 Like

Should I just show you all the entire script?

local Tool = script.Parent;
local plr = script.Parent.Parent.Parent
local opened = script.Parent.opened
local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)

enabled = true




function onActivated()
	if not enabled  then
		return
	end
	if opened.Value == true then
		enabled = false


		Tool.Handle.DrinkSound:Play()
		drink:Play()
		task.wait(5)

		enabled = true

	end
end
enabled = true


function onEquipped()
	if opened.Value == false then
		equip:Play()
		Tool.Handle.OpenSound:Play()
		task.wait(1)
		opened.Value = true
	end
end

function unEquipped()
	local plr = script.Parent.Parent.Parent
	
	drink:Stop()
	
	equip:Stop()
end

script.Parent.Activated:Connect(onActivated)
script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(unEquipped)
1 Like

Can you give a different example because it would make more sense since I gave you the full script

Simple fix can be found here.