The touched event does not fire, it does not play the animation

When the player touches the block the animation is not activated

local part = game.Workspace.Part 

local animation = Instance.new("Animation") 
animation.AnimationId = "ID" 

local humanoid = game.Players.LocalPlayer.Character.Humanoid  

part.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid:LoadAnimation(animation):Play()  
	end
end)

part.TouchEnded:Connect(function(hit)
	local character = hit.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid:LoadAnimation(animation):Stop()  
	end
end)
2 Likes

You need to use the humanoid’s Animator to load the animation. Also, you might want to add a debounce to stop it constantly starting and stopping, because the Touched event fires really quickly multiple times if you don’t.

You might also want to change the animation ID from “ID” to a Roblox asset ID…

1 Like

animation’s animation id is “ID”…uh

2 Likes

Humanoid:LoadAnimation() still works. It’s deprecated but yeah Animator works better

2 Likes

because animationid needs a number not a string

1 Like

I know, just write ID so they can identify it, it still doesn’t work

1 Like

I know, just write ID so they can identify it.

1 Like

Create a local script and put this code and it doesn’t work.
Also place the animation object.

local block = game.Workspace:WaitForChild("Part")
local animation = block:WaitForChild("Caida1") -- "AnimationName" 

local touching = false

block.Touched:Connect(function(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		touching = true
		animation:Play()
	end
end)

block.TouchEnded:Connect(function(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		touching = false
		animation:Stop()
	end
end)

it does not work

1 Like

It’s probably anchored. Touched does not fire if its anchored, so to keep it in place you must use a while loop.

1 Like

idk what you’re on, i have multiple parts anchored and i use a .Touched event for testing purposes and it works

1 Like

Oh maybe Roblox updated their engine then. :grimacing:

Most unlikely. That would break obby games with gamepass pads or the end area.