I need help with food animation

Hi scripters. I’ve ran into a problem while trying to create a food animation system for ice cream. This is the current script I’m using:


local Tool = script.Parent
local EatAnimation = Tool.EatAnimation

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local AnimationTrack = Character.Humanoid:LoadAnimation(EatAnimation)
	AnimationTrack:Play()
end)

For some reason, it doesn’t work when I click while holding the tool. This is what it looks like in studio:

image

As you can see, the parts are welded together. I’m not sure if this is something to do with the script, animation, or what. The animation is a valid animation and I know that. The weird thing is that there are no errors in the output/console. If you guys can help me that would be amazing. Thanks!

1 Like

Its because its inside a tool.Equipped function. Just get rid of that function, and keep the tool.activated part.

Besides, I dont know why you would need a tool.equipped function anyways because the player cant activate a tool if its not equipped lol.

1 Like

Thank you! Honestly, I don’t even know what went through my mind doing that. However, it unfortunately still does not work. This is the script now:

local Tool = script.Parent
local EatAnimation = Tool.EatAnimation

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local AnimationTrack = Character.Humanoid:LoadAnimation(EatAnimation)
	AnimationTrack:Play()
end)

Do you notice anything wrong with this?

You dont have to put Tool.Activated in a Tool.Equipped ya clunkin up yo own code

Maybe use Humanoid.Animator, however, are there any errors?

There are no errors and I’m new to scripting and I don’t know how to use Humanoid.Animator yet. Would you like to try?

-- pretty easy, you just add one little piece of code:
local Tool = script.Parent
local EatAnimation = Tool.EatAnimation

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local AnimationTrack = Character.Humanoid.Animator:LoadAnimation(EatAnimation) -- this is where we change it
-- however, your code might not be working because the animation hasnt loaded. to fix this, you might just be able to do this:
    repeat task.wait() until AnimationTrack.Length > 0.05
	AnimationTrack:Play()
end)

Thanks, I didn’t realize it was that simple. But, it still doesn’t work! At this point I don’t know why…

Can you answer these questions?

is your tool getting randomly deleted from your backpack?
what is the animations priority? if its set to core, it wont be visible. Set it to action.

The tool doesn’t randomly get deleted from my backpack and the animations priority is set to action.

Can you add a print() function inside of tool.activated? Example:

-- pretty easy, you just add one little piece of code:
local Tool = script.Parent
local EatAnimation = Tool.EatAnimation

Tool.Activated:Connect(function()
    print("activated")
	local Character = Tool.Parent
	local AnimationTrack = Character.Humanoid.Animator:LoadAnimation(EatAnimation) -- this is where we change it
-- however, your code might not be working because the animation hasnt loaded. to fix this, you might just be able to do this:
    repeat task.wait() until AnimationTrack.Length > 0.05
	AnimationTrack:Play()
end)

does “activated” print?

Well, imma go to sleep. Hopefully you fix your problem tmrw. See you.

Activated does not print normally, but I found something out. For whatever reason, it works when it’s in the starterpack but not when I get it how I normally get it. It’s very weird…

I solved this by changing the script runcontext to “client”. I don’t even know what this does but it worked.

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