Reducing Lag of Tween


Hey developers, I’ve got a bit of an issue. I have a server sided script that detects when a player is near a door, and then slides the door open. This runs fine in studio but not in the actual game. I believe this is because the script is on the server, so the results don’t get back to the client right away, but i’m not sure. I have barely any other scripts running in the whole game, so I don’t think thats causing it. Can anyone help?

Heres my code

--#Palmtreeninja2

--#Variables
local model = script.Parent
local detector = model.DetectionPart
local left = model.Left
local right = model.Right

--#Positions
local leftOutGoal = {}
local rightOutGoal = {}
local leftInGoal = {}
local rightInGoal = {}

leftInGoal.Position = Vector3.new(3435.78, 1653.271, 4287.452)
rightInGoal.Position = Vector3.new(3439.107, 1653.636, 4290.822)

leftOutGoal.Position = Vector3.new(3432.408, 1653.021, 4284.116)
rightOutGoal.Position = Vector3.new(3442.657, 1653.899, 4294.333)

--#Tween Settings
local TS = game:GetService("TweenService")
local slidetime = 0.75
local slidestyle = Enum.EasingStyle.Sine
local slidedirection = Enum.EasingDirection.Out
local info = TweenInfo.new(slidetime,slidestyle,slidedirection,0,false,0)

--#Tween Tracks
local leftTrackOut = TS:Create(left,info,leftOutGoal)
local rightTrackOut = TS:Create(right,info,rightOutGoal)
local leftTrackIn = TS:Create(left,info,leftInGoal)
local rightTrackIn = TS:Create(right,info,rightInGoal)

local debounce = true --/Debounce

--#Function
local function open()
	if debounce then
		debounce = false
		leftTrackOut:Play();rightTrackOut:Play();wait(slidetime + 1)
		leftTrackIn:Play();rightTrackIn:Play();wait(slidetime)
		debounce = true
	end
end

--#Run
detector.Touched:Connect(open)

I believe this is because the script is on the server, so the results don’t get back to the client right away

That is exactly why. You should have the server fire a RemoteEvent (or change a BoolValue instance) to let players know that a door is opened. Then, the players should TweenService the doors open. Using TweenService on the server is expensive.

I understand your point, though wouldn’t that only open the door for the player, and not for everyone?

Changing a BoolValue would replicate to everyone. RemoteEvent:FireAllClients() would replicate to everyone.

Ahh ok, I will do that. Thank you for your help.