Alright, so when I require a module from a local script and a server script the table’s are two different tables. At first I assumed that they would possibly share a server, but now i’m thinking perhaps due to roblox’s filtering enabled? I’m not sure why, but if anyone could explain how the process of requiring the same modulescript from a server and a localscript works I would appreciate it
When you require a ModuleScript from the server, the server gets its own version of the module; When you require a ModuleScript from the client, each client gets its own version of the module
If the client and server had the same data, that would lead to security vulnerabilities since the server could be easily manipulated by an exploiter (likewise if each client had the same data)
Depends on your use-case, really. For instance: I have a ModuleScript
called SharedUtils
in my ReplicatedStorage
, so it’s replicated to the client upon joining - but it’s also available to the server. Within that script, I have a bunch of functions that are useful to both the client an server. An example being a function that fetches a player’s character by name or player instance:
function module.get_character(duration: number, ...)
duration = duration or 0
-- DECLARE VARIABLES FOR LATER USE
local character: Model
local waited: number = 0
-- ITERATE THROUGH VARIADIC ARGUMENTS
for k, v in pairs({...}) do
-- CHECK CLASS OF CURRENT ITERABLE
if type(v) == "string" then
print(script.Name, "String type found when fetching character")
-- DECLARE VARIABLES FOR LATER USE
local PLYRS: Players = game:GetService("Players")
local plyr: Player
-- WHILE THE PLAYER, CHARACTER ARE NOT FOUND AND TIMEOUT HAS NOT BEEN REACHED,
-- FIND THE PLAYER AND CHARACTER
while not plyr or not character and waited <= duration do
plyr = PLYRS:FindFirstChild(v)
character = plyr.Character
if plyr and character then break end
task.wait(1)
waited += 1
end
return character
-- CHECK CLASS OF CURRENT ITERABLE
else if v:IsA("Player") then
print(script.Name, "Player type found when fetching character")
-- WHILE character IS NIL AND TIMEOUT HAS NOT BEEN REACHED,
-- FIND THE CHARACTER
while not character and waited <= duration do
character = v.Character
if character then break end
task.wait(1)
waited += 1
end
return character
end
end
end
return nil
end
However, as @HugeCoolboy2007 has mentioned: don’t keep stuff that should be executed or stored by the server accessible to the client!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.