Play animation when touching a part

Hello,

So i’m trying to make a teleportation script were if you step on a teleporting part it uses a animation on the player to make it look more realistic now i’m not sure how to code this one ive already made it so it makes a sound Ontouch and that it teleports you towards the other location but now I just need to be able to make it play a new Animation inside of the player so it looks more realistic

2 Likes

I hope I understood what you were trying to do. Here’s some code I wrote.

  • Explorer Tab

Explorer Tab

  • Code
local part = script.Parent

local part2 = script.Parent.Parent.Part2

local id = script.Parent.Parent.AnimID

part.Touched:Connect(function(hit)

	local char = hit.Parent
	local hum = char:WaitForChild("Humanoid")
	local Hrp = char:FindFirstChild("HumanoidRootPart")
	
	local animation = Instance.new("Animation")
	animation.Name="LocalAnimation"
	animation.AnimationId = id
	
	local animtrack = hum:LoadAnimation(animation)
	animtrack:Play()
	
	wait(15)  -- Just to see the animation
	
	if Hrp then
		
		Hrp.Position = part2.Position 
	end

end)
1 Like

Yeah that helped, Huge thanks!

1 Like