Help with door opening after a player presses E on the keyboard

(Sorry if I did this incorrectly)

So I was chilling in Studio when I thought of trying to make a door opening animation.
The problem is… I don’t know how to make it happen if the key pressed detection goes in another script.
Here is my door opening animation:

local TweenService = game:GetService("TweenService")
local door = script.Parent
local userInputService = game:GetService("UserInputService")

local openDoorTweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Bounce,
	Enum.EasingDirection.InOut,
	0,
	false,
	1
)

local ending = 
{
		Orientation = Vector3.new(0,-90,0);
		Position = Vector3.new(-107.5,5,-31.5)		
}

local openDoor = TweenService:Create(door, openDoorTweenInfo, ending)

That works, but now I want to make it happen when a player presses E on their keyboard.
But that only works on a LocalScript (I added a script under the door). How can I achieve this?

Try using a proximity prompt and using the .Triggered Event to play the tween

2 Likes

I tried to do this, but it doesn’t work, it gives me an error saying that “Connect” isn’t a valid member of ProximityPrompt.
Here is what I did (i have proximity prompt beta on, and added it to the door):

local openDoor = TweenService:Create(door, openDoorTweenInfo, ending)

door.ProximityPrompt:Connect(function()
	openDoor:Play()
	
end)

You’re supposed to put .Triggered after the Prompt, like this:

door.ProximityPrompt.Triggered:Connect(function()

end

Use this

local ProximityPrompt = script.Parent
local Door = script.Parent.Parent

ProximityPrompt.Triggered:Connect(function()
if ProximityPrompt.ActionText == “Open” then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = “Close Door”
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = “Open Door”
end
end)