Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Module & Variables?

--ServerScript.

local Admins = {"Vezious"}
local ServerOnlyBans = false -- Allow admins to ban people not in the server with their UserId?
local ReloadTime = 300 -- 5 Minutes, Change to how many seconds it should wait between updating Bans Table
KickMessage = ("This game has shut down.") -- Default Message, You may change this.

require(script.Parent.ModuleScript)

So, what i'm trying to achieve here is to get the variables from the ServerScript and let the Module script use them. Any ideas?

--Module


script = nil
local module = {}


local Event = game.ReplicatedStorage:FindFirstChild("Bans") or Instance.new("RemoteEvent",game.ReplicatedStorage)
Event.Name = "Bans"


local BansTable = nil

function LookForIdPlayer(UserId)
end


function LookForStringPlayer(StringName)
end

function RefreshTable()

end

function CheckAdmin(PlayerName,PlayerID)

end

function Unban(UserId)

end

function Ban(UserId)

end

function CheckStatus(UserId)

end

game.Players.PlayerAdded:connect(function(Player)
if (CheckStatus(Player)) == true  and DisableKickOnJoin == false then
Player:Kick(KickMessage)
end

if Player.UserId ==  game.CreatorId or CheckStatus(Player.Name,Player.UserId) then
print(Player.Name.." Has Joined And Has Admin Access")
Player.Chatted:connect(function(Msg)
end)

while true do

end




return module

2 comments

0

I didn't check the scripts fully, but from what you're saying, it's not possible unless you use global variables.

0

You're in one of those situations where you have to call functions from the server script and do all the variable checks in the server script to make sure the players is banned or is an admin. If you were holding all the variables in the module script then referencing those variables in the server script would then work.

2 answers

✓ Accepted answer

The cleanest way to make this work is to pass the parameters to the module. The module can return a function that takes these in:

-- SERVER SCRIPT
local SetupAdmin = require(themodule)

SetupAdmin(Admins, false, 300, "This game has shut down")
-- MODULE SCRIPT
return function(Admins, ServerOnlyBans, ReloadTime, KickMessage)
	local function CheckAdmin(name)
		......
	end
	......
end


Since that's starting to be a lot of parameters, it probably makes sense to send a table over instead (so that you don't mess up the order / miss one, etc):

-- SERVER SCRIPT
local SetupAdmin = require(themodule)

SetupAdmin {
	Admins = {"Vezious"},
	ServerOnlyBans = false,
	ReloadTime = 300,
	KickMessage = "This game has shut down"
}
-- MODULE SCRIPT
return function(settings)
	local Admins = settings.Admins
	local ServerOnlyBans = settings.ServerOnlyBans
	-- etc....

	local function isAdmin(name)
		-- .....
	end
	-- ......
end

There are a few ways to attempt to get around this, global variables (not recommended) or storing a value outside the script as a physical value such as a BoolValue or a NumberValue. If you where directly sending a variable to the module from another script, that would be easy as functions in modules act just like regular functions but you are trying to fetch a value from a regular script with a module and that won't quite work, it's not a two way door. But if you turned the other script into a module script, you would have no problem (I think).

2 comments

0

Sorry, i've never used global variables, why are they not recommended?

0

It's just not recommended in case you over ride the variable or try to create a variable with the same name.

This discussion is preserved as it was. New answers, comments, and votes are closed.