Help using a proximity prompt to trigger animations

Hi there

I’m trying to make a door open/close with a rotating handle. I tried using Tweens which worked fine for getting the door to open and close, however I couldn’t get the handle to turn using one proximity prompt and it seemed easier to make animations and then script them to be triggered by a proximity prompt.

Here’s the script I have so far:

local OpenAnim = Instance.new("Animation")
OpenAnim.AnimationId = "rbxassetid://6837516143"

local CloseAnim = Instance.new("Animation")
CloseAnim.AnimationId = "rbxassetid://6837521804"

local OpenedAnim = Instance.new ("Animation")
OpenedAnim.AnimationId= "rbxassetid://6840820466"

local animController1 = Instance.new("AnimationController")
local animTrack1 = animController1:LoadAnimation(OpenAnim)

local animController2 = Instance.new("AnimationController")
local animTrack2 = animController2:LoadAnimation(CloseAnim)

local prompt = script.Parent.Door.ProximityPrompt

prompt.Triggered:Connect(function()
	if prompt.ActionText == "Close" then
		animTrack1:Play()
		wait(0.17)
		prompt.ActionText = "Open"
	else
		animTrack2:Play()
		prompt.ActionText = "Close"
	end
end)

The animations here work fine on their own, I just can’t seem to get them to trigger off of this proximity prompt. I’m not a scripter by any means (most of this was cobbled together from YouTube tutorials) so any help you can give would be appreciated.

Thanks!

Please use proper formatting, for example, add spaces between both sides of the = sign.

Anyways, for your issue, you’re creating 2 AnimationControllers. You’re also not parenting the controller to the door, so the controller won’t do anything.

Instead, create a single AnimationController. Parent it to the door. Then, instead of creating another controller for the next track, just use the same AnimationController.