Table Not Storing

Hello.

Currently I have a script that goes through all the modules under a directory. It stores the “Incantation” into a table inside the script that is equal to the module itself, for effiency. I am trying to just store the incantation into a module located in ReplicatedStorage as right now everyone is being scripted in ServerScriptService. For some reason when this runs it stores everything in the script fine but when I try and script with the module in ReplicatedStorage it acts as if nothing is their.

Hopes someone can help!

Server Script

--// Services
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--// Items
--# Objects
local Modules = ReplicatedStorage:FindFirstChild('Modules')
local GlobalStored = require(Modules:FindFirstChild('GlobalStored'))

--# Variables
local groupId = 15625652

local Stored = {}

--// Scripts
--# Chat
Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		local loweredMessage = string.lower(Message)
		for incantation, module in pairs(Stored) do
			if loweredMessage == incantation then
				local rankInGroup = Player:GetRankInGroup(groupId)
				if rankInGroup >= module['Rank'] then
					module['Activate'](Player)
				elseif module['Rank'] == -1 then
					module['Activate'](Player)
				end
			end
		end
	end)
end)

--# Init
function Init()
	
	--# Spell Info
	for _, Spell in ipairs(script.Parent:GetChildren()) do
		if Spell:IsA('ModuleScript') then
			
			Spell = require(Spell)
			
			Stored[Spell.Incantation] = Spell
			
		end
	end
	
	GlobalStored['Incantations'] = Stored
	
	print('Successfully instalized all spells.')
	
end

Init()

ReplicatedStorage Module

local GlobalStored = {
	['Incantations'] = {}
}

return GlobalStored

I need to be able to insert this into the table so it looks like this.
image

Locations:
image

1 Like

If you are calling the GlobalStored module from the client, it won’t see anything, not sure if that is your issue, but maybe that helps.

Yes, I am. Can you not access it from the client since the module is in ReplicatedStorage? What’s a way that I could do it?

Well, considering the Spells are in ServerStorage, only a script or module that is called on Server can access those.

If the Spells are in ReplicatedStorage, then the module, called from either client or server can see them.

However, if you are not wanting them to be copied to all clients, and want to avoid putting spells in ReplicatedStorage, then you will need to use a Remote Event, from the client, requesting the information from the server.

Right so, what I want to happen is inside the ServerScriptService script I have it storing the Incantantation and the module itself but in the ReplicatedStorage module I just want to store the incantation so it looks like this.
image

I need to store the incantation in ReplicatedStorage cause I need to be able to access all of them from the client.