Table returning nil from module scritps

Hi,I am trying to make a "mobile support " for my inventory so basically when I click the button it will clone that Part to my character, anyways.The table is returning nil from “hotbar” variable I don´t know why buy can someone fix it? Also I dont wanna make that the table will repeat insideany loop.

Thanks for help!

Normal script:

-- local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hotbar = script.Parent.Hotbar
hotbarTable = hotbar:GetChildren()

local module = require(script.Parent.ModuleScript)



for _,v in pairs(module.hotbar) do
	if v:IsA("ImageButton") then 

Module script:

local module = {}

module.Loop = function()
	print("This is running")
		module.hotbar = script.Parent.Hotbar:GetChildren()

return module

this one you printed in the normal script

this one is the module script

Do you know scopes?
because you cant just get a value from a function like that

in that case you can use Metatables

And also check out this topic on how to use module scripts more efficently it really helped me to understand how to get variables from tables that are in a function scope, to use metatables.

Oh,Thanks for all I need it is just to update a table without repeating the for i,v in pairs loop do you know how to do smth like that? Should I also watch GnoCode´s video about Metatables?

From what im seeing you’re trying to fire a remote when the player clicks an image

And you’re a bit lucky because you dont actually have use for loops for that

By that i mean the whole purpose of your module script is to get all the children from a ScreenGui (i think)

so instead of using module scripts you could’ve done everything in just 1 script

oh and by the way if this first script you gave me is a Normal Script then FireServer() wont work there you can do it on LocalScripts though.

now for the code i would do something like this:


now i dont exactly know why did you use for loops for this but after that event you can just insert the values you want into a table (even though there are no tables used in these scripts)

let me know if there are any problems

Thanks for that by you I figured it out that I can just put a local script inside that ImageButton that is cloned.And I really just dont need to use for loops.

and it is working perfectly

Big Thanks Again!.

No problem! it would be even better if you marked my idea as “solution” so other scripters with problems like these can search this topic and get help too!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.