Help with modules

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)

I’m confused of the question… are you asking if modules can be used by server and client?

can i use client stuff and import it to a server script like my script above?

(its not working tho)

Module scripts work on both the server and the client but data written to them at runtime will not replicate across the network.

As @player356377 stated module scripts can be accessed by both the client and the server. If you want to replicate a module script from the client to the server you can use Remote Events

i figured the problem it was sending the camera change from the module to the server which ment it was changing the server side’s camera not the client i had to use a remote to send from the server to the client to use the module from the client (thanks to the people that was helping but i tested some stuff in rbx studio and figured it out by accident)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.