Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I use methods in a module script?

Hello,

I would like to find a way to get this method which is supposed to output a table with the raw string values of each airport name to work. Currently not even the method is being triggered/fired.

I would greatly appreciate any help.

My module script:

local airport = {}

airport.destinations = {
	Zakynthos = {
		Name = "Zakynthos";
		IATA = "ZAK"
	}
}

airport.airlines = {
	Airline = {
		Name = "Airline";
		GroupID = 1;
		IATA = "AA";
		Destinations = {
			airport.destinations.Zakynthos;
		}
	}
}

for i, v in ipairs(airport.airlines) do
	
	function v:GetDestinations()
		print("method fired")
		local dest = {}
		for _, x in ipairs(v.Destinations) do
			table.insert(dest, x.Name)
		end
		return dest
	end
	
end

return airport

Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local dest = airportData.airlines.Airline:GetDestinations()

for i, v in ipairs(dest) do
	print(v)
end

Thank you!

1 comment

0

To get a module you must require. so just put local dest = require(airportData.airlines.Airline:GetDestinations). If I knew the answer to your other question, I would put this in an answer. (but i don't)

1 answer

Why do you have a GetDestinations method when you just re-iterate through them? Just iterate through airportData.airlines.Airline.Destinations. There's no point in having a method.

You're just over thinking it, bud.

Hope you can accept this as an answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.