Is there a way to make this smoother?

Hello! I am making this Closet Script. So far it works great and is functional. How ever it is really clunky and even though I am using Tween service, it still looks like it is like stuttering. Any suggestions? Here is what it looks like:
robloxapp-20230426-2235364.wmv (771.0 KB)

Here is the code:

local partStartPos = game.Workspace.SlidingCloDoorBed.Open.Position
local promptUsed = false

local TweenService = game:GetService("TweenService")

local function movePartToNewPos()
	local destination = Vector3.new(-216.8, 35.5, -130.9)
	local tweenInfo = TweenInfo.new(
		3, -- duration of the tween in seconds
		Enum.EasingStyle.Quad, -- easing style of the tween
		Enum.EasingDirection.Out, -- easing direction of the tween
		0, -- number of times to repeat the tween (0 means don't repeat)
		false, -- whether to reverse the tween when it repeats
		0 -- delay before starting the tween in seconds
	)
	local tween = TweenService:Create(game.Workspace.SlidingCloDoorBed.Open, tweenInfo, {Position = destination})
	tween:Play()
end

local function movePartToStartPos()
	local tweenInfo = TweenInfo.new(
		1, -- duration of the tween in seconds
		Enum.EasingStyle.Quad, -- easing style of the tween
		Enum.EasingDirection.Out, -- easing direction of the tween
		0, -- number of times to repeat the tween (0 means don't repeat)
		false, -- whether to reverse the tween when it repeats
		0 -- delay before starting the tween in seconds
	)
	local tween = TweenService:Create(game.Workspace.SlidingCloDoorBed.Open, tweenInfo, {Position = partStartPos})
	tween:Play()
end

game.Workspace.SlidingCloDoorBed.Interact.ProximityPrompt.Triggered:Connect(function()
	if not promptUsed then
		movePartToNewPos()
		promptUsed = true
	else
		movePartToStartPos()
		promptUsed = false
	end
end)

Any ideas?

Sorry for the wmv format. It wouldnt load in mp4.

Are you tweening from the client or the server? If you’re tweening from the server, it will obviously stutter because of latency between the client(s) and the server. If again, you are tweening from the server, I suggest creating a RemoteEvent, and firing to all the clients within the game.

1 Like

Its impossible to see what’s the current behaviour, the video is extremely pixeled, you need to record with a software not the in-built roblox recorder so we can see

1 Like

Sorry I am not that great with Scripting. I think Server Side. I am using just a Script Child’ed under the Part

It’s because you’re tweening from the server. This is why you get this ‘stutter’ effect. I suggest using a RemoteEvent between the client(s) and the server. Here’s a code snippet from one of my games which takes in some tween data, then begins a tween on the client:

-- functions
RemoteEvent.OnClientEvent:Connect(function(data: any)
	if (not data.Instance) then
		return
	end
	
	tweenService:Create(
			data.Instance,
			TweenInfo.new(
				data.TweenInfo.Length,
				Enum.EasingStyle[data.TweenInfo.Style],
				Enum.EasingDirection[data.TweenInfo.Direction],
				data.TweenInfo.Repeats,
				data.TweenInfo.Reverse,
				data.TweenInfo.Delay
			),
			data.Properties
		):Play()
end)

And if you wish to tween something, just fire the RemoteEvent from the server with these data parameters:

RemoteEvent:FireAllClients({
   Instance = -- your door
   TweenInfo = {
      Length = 1,
      Style = "Sine" -- within a string because for some reason you cannot send Enum's through events
      Direction = "Out",
      Repeats = 0,
      Reverse = false,
      Delay = 0,
   },
   Properties = {
      CFrame = ... -- whatever you want to tween just put it in this table
   }
})