So I’ve been wondering, how could I use Module script, that would make doors tweening script play? So far, I have been using doors while in every one of them was a script, but that eventually resulted into too high script activity and game lag. Any sort of help would be very appreciated, as I do not understand module scripts too much. I tried educating at ModuleScript | Documentation - Roblox Creator Hub, but I didn’t really understand it.
Once again, if you could help me, I would be very grateful.
Are the Tweens playing server-side? That usually results in massive game lag, you should always try to play the Tweens client-side.
The tweenservice service is server sided. I persume I will have to make it client sided, as you say. But how do I achieve that?
You’d have to use a RemoteEvent. You could have all doors linked to a single RemoteEvent. When the door is opened/closed, the RemoteEvent is fired with the door that was opened/closed as a parameter. A local script can then receive the request and play a Tween locally. I’m not sure how this would affect the door collisions, though.
Yeah. I am afraid that other players would see the one who passes the door basically pass solid matter, as the tween wouldn’t be played on their client. As such, I think tweening the doors on server would be more optimal in this case and if all the doors were running under one ModuleScript, that might also reduce the lag. If you could help me with making the ModuleScript, I would appreciate that enormously.
You could just use RemoteEvent:FireAllClients(), which would make every client play the Tween. However, players that joined the game after the Tween played probably wouldn’t see the door as open. You could fix that by setting the door’s position to its open state on server-side after playing the Tween. But if you truly must do everything server-side, then you can offload the door Tweens as functions on a module script. It would look something like this:
local module = {}
local TweenService = require(game:GetService("TweenService"))
function module.openDoor(doorModel)
--play opening Tween for doorModel
end
function module.closeDoor(doorModel)
--play closing Tween for doorModel
end
Then each door would have a script similar to this (I’ll just use ClickDetector as an example):
local doorTweens = game:GetService("ServerScriptService").doorTweens
local door = script.Parent.Parent
local isOpen = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if isOpen then
doorTweens.closeDoor(door)
isOpen = false
else
doorTweens.openDoor(door)
isOpen = true
end
end)