What do you want to achieve? I added a sliding door to the boat I made and I need it to be able to tween properly while the boat is moving.
What is the issue? When I open/close the door while the boat is moving it stays relative to the position it was in when the tween started.
Here is a link to a Video of what’s going wrong. I included 2 separate clips, one where the door opens while the boat is anchored and one where the door opens while the boat is moving.
What solutions have you tried so far? I’ve found a few similar topics on the developer hub but they were very unclear and didn’t have a working solution.
Here is a script to reproduce the error which is a child of the door.
local TweenService = game:GetService("TweenService")
--the door has a weld constraint to keep it in place
local door = script.Parent
local doorTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0)
local doorOpenTween = TweenService:Create(door, doorTweenInfo, {Position=door.Position+Vector3.new(0, 0, 7)})
--[[
the door opening is really connected
to a proximity prompt but to make the script
easier to read i had it open after 8 seconds
]]--
wait(8)
doorOpenTween:Play()
Is there any way to keep it relative to its current position after every frame or would I need to try using constraints instead? If so, how would I go about doing that?
local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0)
local doorOpenTween
door:GetPropertyChangedSignal("Position"):Connect(function()
doorOpenTween = TweenService:Create(door, doorTweenInfo, {Position=door.Position+Vector3.new(0, 0, 7)})
end)
task.wait(8)
doorOpenTween:Play()
That’s because when you’re creating the tween you’re using the door’s initial position in the goals table, instead you need to create a new tween each time the position property of the door changes, which you can do so with the “:GetPropertyChangedSignal()” function.
I had a similar requirement recently when creating a Sliding Window model that I wanted to use in multiple places. It worked fine in the location I built it, but when I tried to move and rotate the model to the other side of the building it didn’t work as expected. I messed around with different tweening scenarios and after a few hours I eventually got it working, but the code was ugly, so I switched to a simpler approach and created two transparent duplicates of the sliding part of the model called OpenLocation and CloseLocation. I positioned them appropriately then modified the code to simply tween the CFrame of the sliding part to match one of the transparent parts. Worked like a dream no matter how the model was located or oriented and the code looked much cleaner and easier to maintain later on, which for me are important factors.