Array in module script

Hey. I’m a bit new to modules, and I’m having some issues getting an array from a module with require. I keep getting “Requested module experienced an error while loading” errors. anyone have any suggestions? I’ll specify if requested.

module:

local list = {}

plr = game:GetService("Players").LocalPlayer
gui = plr.PlayerGui
screen = gui.Title.Frame

MenuButtons = {
	screen.start,
	screen.options,
	screen.credits
}

list.Get = function()
	return MenuButtons
end

return list

Dont use global variables please
And please at very least follow scripting standarts etc
Either do that:

local list = {
Get = function() return MenuButtons end
}

or

local function list.Get()
return MenuButtons
end

Also you most likely indexing instances that have not been replicated yet or trying to use own defined globals as upvalues :skull:

TL;DL;
Bro its not a python
Learn how to program
Its a game dev everything has to be written right

Non the less its stuipid having function that you realistically should use only once
Why not return value dirrectly?

First of all, I know less python than I do lua. second, please be respectful. I’m trying my best, and I’ve been blissfully unaware of scripting standards this whole time.

Regardless, thank you. I’ll give this a shot.

5 Likes

Im not disrespectful
that just the way i speak.
Also its Luau not Lua
This languages are very different.

The way you had written a code reminds me a lot about this evil language named “python” habbits people use hence why i assumed that.

1 Like

Ohhh okay, thanks for the clarification. And yes I know the two are different, just a habit of saying Lua. Apologies.

Also, I hate python lol. It’s so slow

2 Likes

i agree with everything else you said but this made me chuckle

3 Likes

Also, how would I go about returning the list directly?

Figured it out, but now I have a different problem.
StarterGui.Title.Frame.sequence:38: attempt to call a nil value

The bottom one causes the error:

list = require(repstor.uiButtons.list)

menu.ShowButtons(list, 1, 0.5, 0)

ShowButtons is not a function inside of menu.

Your error indicates that menu.ShowButtons is a nil value not a function value. You need to make sure menu.ShowButtons points to a function value before attempting to call it.

Dude just put WaitForChild method ts pmo

I’m very sure that I have that function in menu.

Can you show the code within menu? It’s a bit hard to debug that error without seeing how ShowButtons is defined.

If ShowButtons is correctly defined, using the . operator on menu should show it as an option.

This post has a solution now, but yes I am curious why it doesn’t give me an autofill option.

(Also maybe I’ll put a boolean in there and delete the bottom function, because they have the same code lol…)

local menu = {
	ShowButtons = function(buttons, speed, stopTime, targetX)
		for i in buttons do
			yScale = buttons[i].Position.Y.Scale
			uiButtons.ShowButton(buttons[i], speed, targetX, yScale)
			task.wait(stopTime)
		end
	end,

	HideButtons = function(buttons, speed, stopTime, targetX)
		for i in buttons do
			yScale = buttons[i].Position.Y.Scale
			uiButtons.HideButton(buttons[i], speed, targetX, yScale)
			task.wait(stopTime)
		end
	end
}

ts = game:GetService("TweenService")
uiButtons = require(script.Parent)

yScale = nil

return menu

Oops, I sent my response too early,

Looking at your code, this should work perfectly fine. I’ve tested it (removing the code within the functions to prevent any errors) and it worked as intended.

Maybe you’re defining menu incorrectly here:

Like a switcheroo of two variables, but i highly doubt that. I’ve been looking at this code for like 10 minutes, I have no idea what the issue could be!

My best guess is that there might be some other code behind the scenes (the scenes being these code snippets) that may be causing this issue. You’ve correctly defined ShowButtons here.

Where are you defining menu?
If you put print(menu) just before the erroring line, what does it output?

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