In the server, we create just one script to control one classes or more:
-- Server (example script)
local DataManager = require(...)
local AnotherClass = require(...)
local Cache = {}
Players.PlayerAdded:Connect(function(Player)
Cache[player.UserId] = {
DataManager.load(player),
AnotherClass.new(player)
}
end)
However, in the client, when the player joins, each local script are duplicated to player and runs for him, so we have 1 script for 1 module.
local CameraController = require(>...)
CameraController.Follow(anotherPlayer)
task.delay(5, CameraController.Stop)
Why this?
local CameraClass = require(>...)
local CameraObject = CameraClass.new()
CameraObject:Follow(anotherPlayer)
task.delay(5, CameraObject.Stop, CameraObject)
-- THEY ARE THE SAME \_(-.-)_/
I didn’t understand a thing. Are you talking about the client creating a new module each time the player joins? Also this should be in #help-and-feedback:scripting-support
Sorry if i wasnt clear.
In the server we create one script to manage some class and the class manage something, like a data store class to manage player data.
However, in the client, we dont need to manage another clients classes.
-- This is dont necessary, because its just 1 client
local CameraControl = {}
CameraControl.__index = CameraControl
function CameraControl.new(Options)
-- return a class
return setmetatable(class, CameraControl)
end
function CameraControl:Follow()
-- follow script
end
function CameraControl:Stop()
-- stop
end
return CameraControl
Why not
local Camera = workspace.CurrentCamera
local CameraControl = {}
CameraControl.Options = {}
function CameraControl.follow()
-- Follow things
end
function CameraControl.stop()
-- stop thing
end
return CameraControl
idrk but it may have some use cases, like custom camera modes that the player can select from each one behaving differently or 2 characters that the player can switch to each one with a different camera object
but if you don’t need more than 1 camera object then oop is unnecessary in this case
I think you must’ve misunderstood something when learning OOP.
OOP is a style, it is a way of organizing code in your project. Nobody ever said you have to use it.
OOP is useful for when you want objects that manage their own state. In your example, you do not need OOP, since you’ve stated that you will only ever have one instance of your type anyway; but if you, in the future, want to add things like, idk, CameraController:GetCamera(plr) to get camera objects for different players or something, then obviously using OOP would be nicer, since you’d have multiple instances. If it is just going to be a static class, don’t use OOP.