How to make animation play when you touch a part

Does anyone know how to make it so that if you touch a part then an animation plays in another model? for example. I wanna make a cool scripted sequence that triggers an animation when you touch an invisible part. Then like an object infront of you starts moving.

2 Likes

Sample code I wrote since I’m bored

Before this, add the animation you want to play on the model to the part you want to touch

local part = script.Parent
local debounce = false

local model = game.Workspace:WaitForChild("")--- thing you want to animate
local humanoid = model:WaitForChild("Humanoid")

local animation = humanoid.Animator:LoadAnimation(script:WaitForChild(""))---- Name of animation

part.Touched:Connect(function(hit)
    if hit.Parent ~= nil and hit.Parent:FindFirstChild("Humanoid") then
            if debounce == false then
            debounce = true
            animation:Play()
            animation.Stopped:Wait()
            wait(2)
            debounce = false
        end
    end
end)

3 Likes

alright thanks! I’ll try it out.

2 Likes