Trying to run a loop through a module script

is there a way to run a while true do loop through a module script?
when I insert a loop blue and red lines appear under everything. I am trying to update it every few seconds. here is my script.```

local module = {

	Administrators = {
		
	[game.Workspace.OpenVip.OpenSpot1.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot2.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot3.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot4.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot5.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot6.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot7.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot8.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot9.Value] = 1,
	[game.Workspace.OpenVip.OpenSpot10.Value] = 1,
},

Initializer  = ":"

}

return module

The while loop should be in the code that requires the module, not in the module itself. You can’t just insert a loop into a table like that.

For example, let’s say I have this script and this module script:

-- This is the module script

local module = {
    Blah = 25
    Potato = "Cow"
    Pizza = true
}

return module
-- this is the script that requires the module
local Data = require(Module)

This is pretty much what you did:

local module = {
    while true do
        Blah = 25
        Potato = "Cow"
        Pizza = true
    end
}

return module

That doesn’t make sense, you should be putting the loop in the main script instead, like this:

local Data 
while true do
    Data = require(Module)
end

You’re basically trying to run a code inside a table, try using a function instead.

local module = {}

module.Something = function()
module.Initalizer = ':'

while true do
local admins = {}

for _, spot in pairs(workspace:GetChildren()) do
if string.match(spot.Name, 'OpenSpot%d+') then
table.insert(admins, spot.Value)
end
end


module.Administrators = admins
wait(3)
end
end
}

return module
local system = require(path.to.module)
coroutine.wrap(system.Something)() 

print(system.Administrators .. '\n' .. system.Initalizer)

Edit: Since it seem’s that this is inside an admin system try running the module’s function inside the admin’s loader script before the whole system module is required.

(If this isn’t your own admin system your creating)

1 Like

the only scripts using the other scripts are these two

	
local Functions = require(script.Parent.KeyFunctions)
wait(1)

local module = {
	
	
	["GoldSparkles"] = function(input)
		local target = Functions.GetPlayerFromName(input[2])
		local sparkles = Instance.new("Sparkles",target.Character.Head)
		sparkles.SparkleColor = Color3.fromRGB(255, 247, 0)
	end,
	
	
	["Aura"] = function(input)
		local target = Functions.GetPlayerFromName(input[2])
		local aura = Instance.new("Sparkles",target.Character.Head)
		aura.SparkleColor = Color3.fromRGB(255, 247, 0)
	end,
	
}







local function generateModule()
	local newModule = {}
	for key,value in next, module do
		newModule[key:lower()] = value
	end
	return newModule
end

return generateModule()
end

and this one

while true do
	wait(1)

local Settings = require(script:WaitForChild("Settings"))
local Commands = require(script:WaitForChild("CommandsVIP"))

local function parseChat(player, chat)
	if Settings.Administrators[player.Name] or Settings.Administrators[player.UserId] then
		if chat:sub(1,1) == Settings.Initializer then
			local Keywords = chat:sub(2,chat:len()):split(" ")
			local Command = Commands[Keywords[1]:lower()]
			Command(Keywords)
		end
	end
end



game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:connect(function(message, recipient)
		if not recipient then
			parseChat(Player, message)
		end
	end)
	end)
	end

for some reason the commands do not work.

For the second script you posted, it does not need a loop. Try removing the loop.

And for the 1st script remove the last end and remove the wait(1) at the beginning.

I am not like, super good at coding so would you mind telling me what a table is?

so it the first one I already have a table? and the second one doesn’t?