#Tween door models randomly teleporting away when I tween a larger model a few thousand studs

1 messages · Page 1 of 1 (latest)

toxic heron
#

I built this cool train which I want to drive using the tweenservice, which works. The only issue is that the train also has doors that are using tweenservice in order to enter/exit the train. But said doors are randomly disappearing when the train has moved for example 2500 studs away from its original position.
How can I fix this?

#

Train Tween Script

local proximityPrompt = script.Parent.ProximityPrompt
local sound = game.Workspace.ExpressFront.SoundPart.Sound
local sound2 = game.Workspace.ExpressFront.SoundPart.Sound2

local leversound = script.Parent.Sound

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(30, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

local currentPivot = model:GetPivot()
local OpenPosition1 = currentPivot.Position + Vector3.new(-2500,0,0)

local ClosePosition1 = currentPivot.Position + Vector3.new(0,0,0)


local OpenCFrame1 = CFrame.new(OpenPosition1)
local CloseCFrame1 = CFrame.new(ClosePosition1)

local CFrameValue = Instance.new("CFrameValue")

CFrameValue.Parent = script
CFrameValue.Value = currentPivot

local tween1 = TweenService:Create(CFrameValue, TweenInfo, {Value = OpenCFrame1})
local tween3 = TweenService:Create(CFrameValue, TweenInfo, {Value = CloseCFrame1})

proximityPrompt.Triggered:Connect(function()
    if proximityPrompt.ActionText == "Drive" then
        proximityPrompt.Enabled = false
        proximityPrompt.ActionText = "Return"
        
        leversound.Playing = true
        wait(1)
        
        tween1:Play()
        sound.Playing = true
        wait(9)
        sound2.Playing = true
        wait(10)
        proximityPrompt.Enabled = true
        sound2.Playing = false
    else
        proximityPrompt.ActionText = "Drive"
        proximityPrompt.Enabled = false
        
        leversound.Playing = true
        wait(1)
        tween3:Play()
        sound.Playing = true
        wait(9)
        sound2.Playing = true
        wait(10)
        proximityPrompt.Enabled = true
        sound2.Playing = false
    end
end)

CFrameValue.Changed:Connect(function(val)
    model:PivotTo(val)
end)

tween1.Completed:Connect(function()
    CFrameValue.Value = OpenCFrame1
end)

tween3.Completed:Connect(function()
    CFrameValue.Value = CloseCFrame1
end)```
#

One of two tween train doors for passengers

local proximityPrompt = script.Parent.Button.ProximityPrompt
local proximityPrompt2 = script.Parent.Parent.TrainButton2.Button.ProximityPrompt

local sound = script.Parent.Parent.TrainDoor.SoundPart.Sound
local sound2 = script.Parent.Parent.TrainDoor.Door.Base.Sound
local sound3 = script.Parent.Parent.TrainDoor.Door.Base.Sound2

local part = script.Parent.Button
local part2 = script.Parent.Parent.TrainButton2.Button
local light = script.Parent.Parent.TrainDoor.SoundPart

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)

local currentPivot = model:GetPivot()
local OpenPosition1 = currentPivot.Position + Vector3.new(0,0,0.75)
local OpenPosition2 = currentPivot.Position + Vector3.new(5,0,0.75)
local ClosePosition1 = currentPivot.Position + Vector3.new(0,0,0.75)
local Closeposition2 = currentPivot.Position + Vector3.new(0,0,0)

local OpenCFrame1 = CFrame.new(OpenPosition1)
local OpenCFrame2 = CFrame.new(OpenPosition2)
local CloseCFrame1 = CFrame.new(ClosePosition1)
local CloseCFrame2 = CFrame.new(Closeposition2)

local CFrameValue = Instance.new("CFrameValue")

CFrameValue.Parent = script
CFrameValue.Value = currentPivot

local tween1 = TweenService:Create(CFrameValue, TweenInfo, {Value = OpenCFrame1})
local tween2 = TweenService:Create(CFrameValue, TweenInfo, {Value = OpenCFrame2})
local tween3 = TweenService:Create(CFrameValue, TweenInfo, {Value = CloseCFrame1})
local tween4 = TweenService:Create(CFrameValue, TweenInfo, {Value = CloseCFrame2})

local function toggleAlarmLight(times, interval)
    for i = 1, times do
        light.BrickColor = BrickColor.new("Persimmon")
        
        wait(interval)
        
        light.BrickColor = BrickColor.new("Black")
        
        wait(interval)
    end
end```
#
    if proximityPrompt.ActionText == "Open" then
        part.BrickColor = BrickColor.new("Black")
        part.PointLight.Enabled = false
        proximityPrompt.Enabled = false
        proximityPrompt.ActionText = "Close"
        part2.BrickColor = BrickColor.new("Black")
        part2.PointLight.Enabled = false
        proximityPrompt2.Enabled = false
        proximityPrompt2.ActionText = "Close"
        tween1:Play()
        sound3.Playing = true
        wait(2)
        tween2:Play()
        sound2.Playing = true
        wait(1.7)
        part.BrickColor = BrickColor.new("Steel blue")
        part.PointLight.Enabled = true
        proximityPrompt.Enabled = true
        part2.BrickColor = BrickColor.new("Steel blue")
        part2.PointLight.Enabled = true
        proximityPrompt2.Enabled = true
    else
        part.BrickColor = BrickColor.new("Black")
        part.PointLight.Enabled = false
        proximityPrompt.Enabled = false
        proximityPrompt.ActionText = "Open"
        part2.BrickColor = BrickColor.new("Black")
        part2.PointLight.Enabled = false
        proximityPrompt2.Enabled = false
        proximityPrompt2.ActionText = "Open"
        sound.Playing = true
        toggleAlarmLight(15,0.06)
        sound2.Playing = true
        tween3:Play()
        toggleAlarmLight(15,0.06)
        tween4:Play()
        sound3.Playing = true
        sound.Playing = false
        wait(1)
        part.BrickColor = BrickColor.new("Steel blue")
        part.PointLight.Enabled = true
        proximityPrompt.Enabled = true
        part2.BrickColor = BrickColor.new("Steel blue")
        part2.PointLight.Enabled = true
        proximityPrompt2.Enabled = true
    end
end)

CFrameValue.Changed:Connect(function(val)
    model:PivotTo(val)
end)```
#
    CFrameValue.Value = OpenCFrame1
end)

tween2.Completed:Connect(function()
    CFrameValue.Value = OpenCFrame2
end)

tween3.Completed:Connect(function()
    CFrameValue.Value = CloseCFrame1
end)

tween4.Completed:Connect(function()
    CFrameValue.Value = CloseCFrame2
end)```
hearty mural
#

I assume you call the doors CFrame once, meaning instead of current position after the train moved, the tweenservice uses the previous CFrame.

#

You'll have to make it so the CFrame updates every time you want to open and close the doors.