Getting Variables from a Module Script

I just got into ModuleScripts as I shoot to making tech configuration easier, but I’m stuck on a constant issue.

[1] What are you trying to achieve?
Trying to simply get a variable (GroupLockEnabled & GroupID) from a module script to a normal script in workspace.

[2] What is the issue?
I keep on getting errors that include, CoreScript:20: attempt to concatenate string with nil .

[3] What are some solutions that you have tried?
I’ve tried the following:

  • Looking around DevForum
  • Searching around Roblox’s API

[4] Main Script
Below includes both the module and standard script.

Module Script (SystemConfig):

local Settings = {}
																											local Settings = {}
--Tweening
Settings.EasingStyle = Enum.EasingStyle.Linear --The style in which the tween will act to. ( eg. Enum.EasingStyle.Linear )
Settings.EasingDirection = Enum.EasingDirection.In --The direction of the tween. ( eg. Enum.EasingDirection.InOut )
Settings.TweenSpeed = 0.75 --The speed in which the tween will play.

--Group Lock , STARTING RIGHT HERE! \/
Settings.GroupLockEnabled = true --Restricts non-group members from using the admin board
Settings.GroupID = 10238868 --If you are using a group, replace "0" with the Group's ID. 
Settings.MinRank = 255 --The minimum rank that is allowed to use the admin board

--Date and time
Settings.TimeEnabled = true --Turns on the date and time reader on the screens
Settings.GameTime = true --If gameTime is enabled, local time will be disabled

--Descriptions
Settings.Muster = [[A muster drill is currently being held, please report to Deck 5. 

*This drill is REQUIRED before cruising. ]]

Settings.Offline = [[404: CONNECTION LOST]]

return {Settings = Settings}

Main Script (CoreScript)

--Settings
local Module = script.Parent.Parent:WaitForChild("SystemConfig")
local Settings = require(Module)

---MAIN VARIABLES
local Main = script.Parent.Parent.Parent.ShipScreenSystem
local Admin = Main.AdminBoard
local allScreens = Main.Screens



---OnJoinScript
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

warn([[SCREEN SYSTEM HAS SUCCESSFULLY LOADED.

GroupEnabled: ]]..Settings.GroupLockEnabled) ---ERROR HERE

if not LocalPlayer:GetRoleInGroup(Settings.GroupID) >= Settings.MinRank then
	Admin:Destroy()
end

I appreciate any little help! <3

Did you mean:

return Settings
2 Likes

I’ve tried changing the return { Settings = Settings} , however another error appears in the same line which includes:

attempt to concatenate string with boolean

Could you elaborate on what you mean? Do you mean the Settings.Settings.GroupLockEnabled or the loading of the module entirely?

You’ll need to tostring the bool value.

warn([[SCREEN SYSTEM HAS SUCCESSFULLY LOADED.

GroupEnabled: ]].. tostring(Settings.GroupLockEnabled))
2 Likes

Replace the part I quoted with “Settings”, if you want you can also do “Settings.Settings.GroupLockEnabled” in your main script but it look’s a bit strange.

This seems to have worked, but I have one final question before I wrap up this topic:
For further usage of variables, will I have to use the “tostring()” each time when I get a setting’s value?

If your concatenating a boolean or enum then yes.

1 Like

Alrighty, well thanks for the nice and speedy response (both of you), I’ll go ahead and mark this thread.