My animation script isn't working

Hi, I recently made an animation and when I tested in a separate game in-studio it was working fine.
Testing area - Roblox Studio - Gyazo
As you can see it works fine here. However, when I test in-game and in-studio of my actual game the animation fails to play. It is a group game so I did place the animation within my group and I have set the animation priority to action. Also, I waited a day just in case roblox may have needed time to verify it and I re-uploaded the animation yet it still doesn’t work. Thus, I believe there is a problem with the script itself.

local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local animation = script.Parent:FindFirstChild("Animation")
local eatAnim = character:WaitForChild("Humanoid"):LoadAnimation(animation)
local sound = script.Parent:FindFirstChild("Eat sound")

local canEat = true

script.Parent.Activated:Connect(function(plr)
	if canEat then
		canEat = false
		eatAnim:Play()
		wait(.2)
		sound:Play()
		wait(1)
		canEat = true 
	end
end)

Thank you.

Maybe replace your code with this?

local tool = script.Parent
local animation = tool:FindFirstChild("Animation")
local sound = tool:FindFirstChild("Eat sound")

local canEat = true

local char,hum,eatAnim

tool.Equipped:Connect(function()
	char = tool.Parent
	hum = char:FindFirstChildOfClass("Humanoid")
	if hum and not eatAnim then
		eatAnim = hum.Animator:LoadAnimation(animation)
	end
end)

tool.Activated:Connect(function()
	if not canEat then return end
	canEat = false
	eatAnim:Play()
	wait(.2)
	sound:Play()
	wait(1)
	canEat = true 
end)

Not sure how much it’ll work but I think it could be that CharacterAdded still waiting for the character to exist, so I think it’s best if you set the EatAnim the first time it is equipped. If this doesn’t work then I think it’s something up with the animation

1 Like


I got these errors

What’s in your Origiri tool? I think it may be a simple name error

image
Here’s the hierarchy

Try replacing the FindFirstChild in the animation and sound variables to be WaitForChild

local tool = script.Parent
local animation = tool:WaitForChild("Animation")
local sound = tool:WaitForChild("Eat sound")

Judging by the error on line 13, it’s probably that the Animation instance hasn’t been created yet by the time the script activated

1 Like

You’ve saved the day once again! Here’s a preview of the animation since you deserve to see it:
Gyazo
(It’s kinda loud lol)

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like