Module script issue

Basically I have a value stored which is utilized by a if statement however it’s not working.

Heres my script:

loginbutton.MouseButton1Click:Connect(function()
	if rankbox == settings.ranks then
		loginbutton.Text = "Logged in as a Supervisor"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = true
		callsignbox = callsign
	else
		loginbutton.Text = "Logged in as a Officer"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = false
		callsignbox = callsign
	end
end)

Heres my module script:

local module = {
	ranks = "Sergeant"
}


return module

Essentially what the script is meant to do is check if the textbox text = “Sergeant” which is stored in the module then carry out the function however it is not working.

Can you send the full script?


--- Module Variables
local module = game:GetService("ReplicatedStorage").Settings
local settings = require(module)

--- Login Frame

local callsignbox = script.Parent.LoginFrame.MainFrame.CallsignBox.Text
local rankbox = script.Parent.LoginFrame.MainFrame.RankBox.Text
local loginbutton = script.Parent.LoginFrame.MainFrame.LoginButton
local pnc = script.Parent.Parent["Police National Computer"]
local loginframe = pnc.LoginFrame
local supervisor = pnc.LoginFrame.MainFrame["IsASupervisor?"]
local callsign = pnc.LoginFrame.MainFrame.CallSign.Value

loginbutton.MouseButton1Click:Connect(function()
	if rankbox == settings.ranks then
		loginbutton.Text = "Logged in as a Supervisor"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = true
		callsignbox = callsign
	else
		loginbutton.Text = "Logged in as a Officer"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = false
		callsignbox = callsign
	end
end)

Try printing rankbox and settings.ranks. Do some debugging.

I have there’s no errors at all so I presume it’s an issue with the module?

fixed it, just needed to change a variable

1 Like

Can you do some debugging? Add a print every line or so, and tell me which line it doesn’t print.

loginbutton.MouseButton1Click:Connect(function()
	if rankbox == settings.rank1 then
		loginbutton.Text = "Logged in as a Supervisor"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = true
		callsignbox = callsign
	else
		loginbutton.Text = "Logged in as a Officer"
		wait(0.4)
		loginframe.Visible = false
		supervisor.Value = false
		callsignbox = callsign
	end
end)
local module = {}

module.rank1 = "Sergeant"

return module

what if i wanted to add multiple ranks?

-- modulescript in game.ReplicatedStorage called Ranks

return {
	"Private",
	"Private First Class",
	"Corporal",
	"Specialist",
	"Sergeant",
	"Staff Sergeant",
}

local ranks = require(game.ReplicatedStorage.Ranks)

-- print all ranks
for i, rank in ipairs(ranks) do
	print(i, rank)
end

local player = game.Players.LocalPlayer
local playerRank = player.Rank.Value -- intValue

-- print the local players rank
print(ranks[playerRank])
local module = {}

module.rank1 = "Sergeant"
module.rank2 = "Supervisor"
module.rank3 = "Officer"

return module

And just edit the script to be changed to the rank, for example:

if rankbox == settings.rank2 then

if rankbox == settings.rank3

etc… The same as your current script, but just change the value to the value you want from the module script.

This is inefficient, simply because if you had 100 ranks, you would have to check 100 if statements and that’s alot of pain.

I’m getting an error now "invalid argument #1 to pairs (table expected, got string)

Whose solution did you choose?

I experimented with my own solution which was using table.find