so. i was wondering does modules have the power to be server and client things.?
i am trying to organize so i am starting to use modules but i dont understand them that well can someone help?
so this is my module script
local module = {}
----------------------------------------------------------------------------------------------------
-- Variable
----------------------------------------------------------------------------------------------------
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemotesFold = ReplicatedStorage:WaitForChild("Remotes")
----------------------------------------------------------------------------------------------------
-- Camera Function
----------------------------------------------------------------------------------------------------
function module.Camera(on)
local camera = workspace.CurrentCamera
local Folder = workspace:WaitForChild("ViewerFolder"):WaitForChild("Map")
local overview = Folder:WaitForChild("Overview1")
if on then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = overview.CFrame
else
camera.CameraType = Enum.CameraType.Custom
end
end
return module
and this is my server script
----------------------------------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------------------------------
local DataStoreService = game:GetService("DataStoreService")
local DataBase = DataStoreService:GetDataStore("Data")
local SessionData = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModuleFold = ReplicatedStorage:WaitForChild("Modules")
local MainModule = require(ModuleFold.Main)
----------------------------------------------------------------------------------------------------
-- Player Added Event
----------------------------------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(function(plr)
----------------------------------------------------------------------------------------------------
-- Character Added Event
----------------------------------------------------------------------------------------------------
plr.CharacterAdded:Connect(function(char)
for _, v in ipairs(char:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
MainModule.Camera(true)
end)
----------------------------------------------------------------------------------------------------
-- Create Leaderstats and Inventory Folders
----------------------------------------------------------------------------------------------------
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local pleaderstats = Instance.new("Folder")
pleaderstats.Name = "pleaderstats"
pleaderstats.Parent = plr
local inventory = Instance.new("Folder")
inventory.Name = "inventory"
inventory.Parent = plr
----------------------------------------------------------------------------------------------------
-- Load Player Data
----------------------------------------------------------------------------------------------------
local success, playerdata
local attempt = 1
repeat
success, playerdata = pcall(function()
return DataBase:GetAsync(plr.UserId)
end)
attempt += 1
if not success then
warn(playerdata)
task.wait(3)
end
until success or attempt == 5
if success then
print("Data Loaded for: " .. plr.Name)
if not playerdata then
warn("Failed loading for: " .. plr.Name .. ", Assigning default data..")
playerdata = {
["Kills"] = 0,
["Guns"] = {"AR"},
}
end
SessionData[plr.UserId] = playerdata
else
warn("Couldn't Load any data for: " .. plr.Name)
plr:Kick("Unable to load your data, please rejoin")
end
----------------------------------------------------------------------------------------------------
-- Function to Add Value
----------------------------------------------------------------------------------------------------
local function addValue(itemType, itemName, defaultValue, visible)
local parentFolder = visible and plr.leaderstats or plr.pleaderstats
local item = Instance.new(itemType)
item.Name = itemName
item.Parent = parentFolder
playerdata[itemName] = defaultValue
item.Value = SessionData[plr.UserId][itemName]
end
addValue("NumberValue", "Kills", 0, true)
end)
----------------------------------------------------------------------------------------------------
-- Player Removing Event
----------------------------------------------------------------------------------------------------
game.Players.PlayerRemoving:Connect(function(plr)
if SessionData[plr.UserId] then
local success, errormsg
local attempt = 1
repeat
success, errormsg = pcall(function()
DataBase:SetAsync(plr.UserId, SessionData[plr.UserId])
end)
attempt += 1
if not success then
warn(errormsg)
task.wait(3)
end
until success or attempt == 5
if success then
print("Data saved for: " .. plr.Name)
else
warn("Unable to save for: " .. plr.Name)
end
end
end)