I am currently working on a game. It has a lot of doors that rely on the Tweening Service and CFrame, So every time a door animation plays for a certain door, when it was built the Door and Other objects weren’t in the same Orientation as they are now.
So basically what is happening is that when playing a Tween Animation the Door will reset to it’s original orientation thus making the door stick out of the wall.
Is there anyway I can stop this from happening or will I have to entirely recreate the door?
The Script
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent.Parent.Door
local TweenService = game:GetService("TweenService")
local tweeningInfo = TweenInfo.new(
5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
false,
0
)
local tweenOpen = {CFrame =CFrame.new(-591.214, 43.204, -102.568)}
local tweenClose = {CFrame = CFrame.new(-591.214, 36.504, -102.568)}
local OpenTween = TweenService:Create(Door, tweeningInfo, tweenOpen)
local CloseTween = TweenService:Create(Door, tweeningInfo, tweenClose)
ProximityPrompt.Triggered:Connect(function()
script.Parent.Light.BrickColor = BrickColor.new("Lime green")
OpenTween:Play()
ProximityPrompt.MaxActivationDistance = 0
wait(10)
script.Parent.Light.BrickColor = BrickColor.new("Bright red")
CloseTween:Play()
wait(5)
ProximityPrompt.MaxActivationDistance = 10
end)
If we assume that the door is initially closed, we only need to find the offset (with :ToObjectSpace) and add it to the initial position of the current door.
local position1 = CFrame.new(-591.214, 43.204, -102.568) -- open
local position2 = CFrame.new(-591.214, 36.504, -102.568) -- closed. original initial position
local tweenOpen = {CFrame = Door.CFrame * position2:ToObjectSpace(position1)} -- position2:ToObjectSpace(position1) is the offset
local tweenClose = {CFrame = Door.CFrame}
This doesn’t work either. Also are you sure that’s a proper variable, I am not judging you or anything it’s just that I have never seen anyone use that before.
I also got this error in the output: GoTo is not a valid member of UnionOperation "Workspace.Door.Door"
local ProximityPrompt = script.Parent
local openTarget = game.Workspace.Target -- Change Here
local Door = script.Parent.Parent.Parent.Door
local originalCFrame = Door.CFrame
local TweenService = game:GetService("TweenService")
local tweeningInfo = TweenInfo.new(
5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
false,
0
)
local openTween = {CFrame = openTarget.CFrame}
local closeTween = {CFrame = originalCFrame}
local tweenOpen = {Door, tweeningInfo, openTween}
local tweenClose = {Door, tweeningInfo, closeTween}
Workspace.Door.KeycardReader.ProximityPrompt.OpenClose:28: attempt to call a nil value
Which is weird because Line 28 is not a Nil value
Current Script:
local ProximityPrompt = script.Parent
local openTarget = game.Workspace.Target -- Change Here
local Door = script.Parent.Parent.Parent.Door
local originalCFrame = Door.CFrame -- Also, this would be set once the server begins and kept that way, correct?
local TweenService = game:GetService("TweenService")
local tweeningInfo = TweenInfo.new(
5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
false,
0
)
local openTween = {CFrame = openTarget.CFrame}
local closeTween = {CFrame = originalCFrame}
local tweenOpen = {Door, tweeningInfo, openTween}
local tweenClose = {Door, tweeningInfo, closeTween}
ProximityPrompt.Triggered:Connect(function()
script.Parent.Light.BrickColor = BrickColor.new("Lime green")
tweenOpen:Play() -- Line 28
ProximityPrompt.MaxActivationDistance = 0
wait(10)
script.Parent.Light.BrickColor = BrickColor.new("Bright red")
tweenClose:Play()
wait(5)
ProximityPrompt.MaxActivationDistance = 10
end)
local TweenService = game:GetService("TweenService")
local ProximityPrompt = script.Parent
local openTarget = game.Workspace.Target -- Change Here
local Door = script.Parent.Parent.Parent.Door
local originalCFrame = Door.CFrame
local TweenService = game:GetService("TweenService")
local tweeningInfo = TweenInfo.new(
5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
false,
0
)
local openTween = {CFrame = openTarget.CFrame}
local closeTween = {CFrame = originalCFrame}
local tweenOpen = TweenService:Create(Door, tweeningInfo, openTween)
local tweenClose = TweenService:Create(Door, tweeningInfo, closeTween)
Make sure the target part (game.Workspace.Target) is aligned properly. You should just duplicate the Door part and use that as the target part so you know the orientations are already correct
I have had the issue previously and could not find any solutions and I have had to restart my entire developing process in my game over. It had only just recently came to me to ask the DevForum.
So thank you and to everyone else who tried helping, it is greatly appreciated!