Tweens act weird between clients

Hello.

I am attempting to create an elevator for a game I am making but have discovered a strange issue.
When I add a new player to the local studio test, (basically simulating playing as another person) while the tween is going, the tweened objects seem to be misplaced. I cannot figure out why this is occurring. I use tweens for a lot in my games, and I suspect this issue exists in those games too.

Does anyone know what I can do to solve this?
Attached is a video of the issue itself the script for the elevator, and the structuring.
image
image

Look like tweens behaving inconsistently between clients in Roblox can result from various factors, including how tweening is handled in the client-server model. Here are the most common reasons and potential solutions:

Common Causes

  1. Tween Run on the Client:
  • Tweens are typically executed on the client because they involve UI or local effects. However, if different clients start the tween at slightly different times or under varying conditions, the behavior will look inconsistent.
  1. Network Latency:
  • If you’re tweening something that affects all players (e.g., an in-game object), running the tween locally on each client might cause visible desynchronization due to network delay or differences in when each client starts the tween.
  1. Object Ownership:
  • Tweens involving physics-based objects (e.g., a part that moves) can behave inconsistently because the server and clients handle physics differently based on part ownership.
  1. Non-Synchronized Timelines:
  • If the tween is triggered at a specific time and relies on the client’s local clock, minor time discrepancies can result in inconsistent playback.

Solutions

  1. Run Tweens on the Server:
  • If the tween involves shared objects, run it on the server to ensure all clients see the same result. Note that this can introduce slight latency, so it’s best for non-UI elements.
local TweenService = game:GetService("TweenService")
local part = workspace.Part -- Example part

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local goal = {Position = Vector3.new(10, 5, 0)}

local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
  1. Use Remote Events for Synchronization:
  • Trigger the tween simultaneously on all clients using a RemoteEvent. Ensure all clients receive the event at roughly the same time.Server:
local RemoteEvent = game.ReplicatedStorage.TweenEvent

RemoteEvent:FireAllClients(goalPosition)

3.Client:*

local TweenService = game:GetService("TweenService")
local RemoteEvent = game.ReplicatedStorage.TweenEvent

RemoteEvent.OnClientEvent:Connect(function(goalPosition)
    local part = workspace.Part
    local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    local goal = {Position = goalPosition}

    local tween = TweenService:Create(part, tweenInfo, goal)
    tween:Play()
end)
  1. Anchor Physics Objects:
  • For moving parts, ensure they are anchored during the tween and unanchored afterward to prevent physics discrepancies.
  1. Preload Assets:
  • If you’re tweening UI or other client-side assets, make sure they are fully loaded before starting the tween.
  1. Debug Timing Issues:
  • Print timestamps or use os.clock() to verify when the tween starts on each client. This helps identify discrepancies in tween initiation.

Additional Considerations

  • TweenService Limitations: Tweens are purely visual and don’t affect physics simulations. For movement tied to gameplay, consider using CFrames or custom scripts.
  • Replication Lag: If the issue is purely visual, minor lag between clients might still be acceptable. Prioritize gameplay consistency over visual fidelity when necessary.