I am currently attempting to create an elevator that opens after a few seconds once you activate the proximity prompt. At first, it didn’t work at all because it was anchored, so I had to unanchor it. When I unanchored it, it would move to its current position. As in, when I tipped the door over and I clicked the button, it would return to its original position instead of moving to the left by the width of the door. Is there anything wrong with the script below? How can I get my door to move left and how can I keep it anchored so it doesn’t fall over?
local model = script.Parent
local LeftDoor = model.ElevatorDoor1
local RightDoor = model.ElevatorDoor2
local prompt = model.ElevatorButton.Attachment.ProximityPrompt
local tweenInfo = TweenInfo.new(1)
local leftGoalOpen = {}
local leftGoalClose = {}
leftGoalOpen.CFrame = LeftDoor.CFrame * CFrame.new(LeftDoor.Size.X, 48.616, -17.91)
leftGoalClose.CFrame = LeftDoor.CFrame
local leftTweenOpen = TweenService:Create(LeftDoor, tweenInfo, leftGoalOpen)
local leftTweenOpen = TweenService:Create(LeftDoor, tweenInfo, leftGoalClose)
prompt.Triggered:Connect(function()
leftTweenOpen:Play()
end)
Tweens should still work even when parts are anchored, as they merely update a property over time. Changing the CFrame of a part is not affected by whether the part is anchored or not.
I don’t 100% understand what you’re explaining, but from the code, I do notice that you define leftTweenOpen twice with the code:
local leftTweenOpen = TweenService:Create(LeftDoor, tweenInfo, leftGoalOpen)
local leftTweenOpen = TweenService:Create(LeftDoor, tweenInfo, leftGoalClose)
From the looks of it, seems like you meant to set the second variable to leftTweenClose instead of leftTweenOpen. That would certainly affect the result of your code.
If you’re still having issues, try sending a video so we can better understand what is going on.
I see nothing wrong with your code now. This is really odd. One thing I suggest you check is the coordinates of the left door goal tween. Are you sure the door is tweening to the right CFrame?
Hello, the open and close variable have the same name, since the close variable came after the open the close is prioritized and is the one play.
so basically you were closing the door instead of opening it
local model = script.Parent
local LeftDoor = model.ElevatorDoor1
local RightDoor = model.ElevatorDoor2
local prompt = model.ElevatorButton.Attachment.ProximityPrompt
local tweenInfo = TweenInfo.new(1)
local leftGoalOpen = {}
local leftGoalClose = {}
leftGoalOpen.CFrame = LeftDoor.CFrame * CFrame.new(LeftDoor.Size.X, 48.616, -17.91)
leftGoalClose.CFrame = LeftDoor.CFrame
local leftTweenOpen = TweenService:Create(LeftDoor, tweenInfo, leftGoalOpen)
local leftTweenClose = TweenService:Create(LeftDoor, tweenInfo, leftGoalClose)
prompt.Triggered:Connect(function()
leftTweenOpen:Play()
end)
here is a fixed version
also, why do you have a close tween? if you wanna close the door after the door opened you can do something like this:
prompt.Triggered:Connect(function()
leftTweenOpen:Play()
leftTweenOpen.Completed:Wait()
Wait(5) -- delay, this will close 5 seconds after the door opened
leftTweenClose:Play() -- play the tween that closes the door
end)
IMPORTANT: MAKE SURE THE ELEVATOR IS ANCHORED, THAT MAY BE THE REASON THE DOOR IS FLINGING EVERYWHERE.
oh and also add some debounce or people gonna spam that
Yes, its moving from its origin position (56.492, 48.616, -17.91) to (59.075, 48.616, -17.91) which is just slightly to the left. It is anchored and should just move slightly, but instead it flings yonder.
Its now fixed and I plan to have the door close once the player enters (its for a single player horror game so for it to work well I want it to close on queue) The flinging still occurs, I’m still unsure as to whats happening
I think the issue is the coordinates of your tween. By your code, this line: leftGoalOpen.CFrame = LeftDoor.CFrame * CFrame.new(LeftDoor.Size.X, 48.616, -17.91)
sets the final CFrame of the door to an offset of the original CFrame by 48 STUDS UP, which is why your door goes up.
Try changing the goal to something like this: leftGoalOpen.CFrame = LeftDoor.CFrame * CFrame.new(LeftDoor.Size.X, 0, 0)
If that doesn’t work try this instead: leftGoalOpen.CFrame = LeftDoor.CFrame * CFrame.new(-LeftDoor.Size.X, 0, 0)
Yea, I was able to figure this out. I assumed that I had to put in the exact coordinates instead of giving the amount I actually wanted it to move. I really appreciate the help!