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)
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…
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)