Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is part tweening to previous position in replicated storage?

Asked by 3 years ago
Edited 3 years ago

So I have a door that is part of a room. It has a button with a script that tweens the door to the left (Opening the door), and that also tweens it back into it's initial position (Closing the door).

I keep the room in replicated storage and I clone multiple copies of it. Then I change the CFrame of each room to stack them on top of each other.

When in game, and I press the button they all tween to the location they were set to before being put in replicated storage.

Here's the code that tweens it,

doorTween = {}

door = script.Parent:WaitForChild("Door")
doorPos = door.Position

local TweenService = game:GetService("TweenService")

-- Tweening info ---------------------------------------------------------
local goalOpen = {}
goalOpen.Position = Vector3.new(door.Position.X + 5.501, door.Position.Y, door.Position.Z - 4.95)

local goalClosed = {}
goalClosed.Position = doorPos

local tweenInfo = TweenInfo.new(3)

local tweenOpen = TweenService:Create(door, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(door, tweenInfo, goalClosed)
--------------------------------------------------------------------------

-- Add a few functions to the table
function doorTween.playCloseDoor()
    tweenClose:Play()
end

function doorTween.playOpenDoor()
    tweenOpen:Play()
end

return doorTween

Edit: Script that plays the tweens,

local doorFunctions = require(script.Parent.DoorTweenModule)

local lock = script.Parent:WaitForChild("Lock")

local outButton = script.Parent:WaitForChild("OutButton")
local inButton = script.Parent:WaitForChild("InButton")

local clickDetectorOut = outButton.Button:WaitForChild("ClickDetector")
local clickDetectorIn = inButton.Button:WaitForChild("ClickDetector")

local isOpen = false

clickDetectorOut.MouseClick:Connect(function()
    if(not lock.Value) then
        if(isOpen) then
            doorFunctions.playCloseDoor()
        else
            doorFunctions.playOpenDoor()
        end
        isOpen = not isOpen
    end
end)

clickDetectorIn.MouseClick:Connect(function()
    if(not lock.Value) then
        if(isOpen) then
            doorFunctions.playCloseDoor()
        else
            doorFunctions.playOpenDoor()
        end
        isOpen = not isOpen
    end
end)
1
Please include the script that plays the tweens. deeskaalstickman649 475 — 3y

Answer this question