Attempt to get length of a nil value

Ok so I’m trying to get a random name out of a table here is the script

local module = {}
local serverstorage = game:GetService("ServerStorage")

local MasculineNames = require(script.Masculine)
local FeminineNames = require(script.Feminine)
local DevNames = require(script.DeveloperNames)
local SpecNames = require(script.SnowChosenNames)



function module.FirstName(Male)
	local v2
	
	if Male == true then
		v2 = MasculineNames
		
	elseif Male == false then
		v2 = FeminineNames
	end
	
	return v2[math.random(1,#v2)]

end

return module

The error occurs on this line

return v2[math.random(1,#v2)]

1 Like

Could you send the code of both of the modulescripts your using to assign v2 to

return { "Aang", "Abel", "Adam", "Abraham", "Adrian", "Aesop", "Agravain", "Ahab", "Ajax", "Alan", "Alexander", "Alonso", "Alphonse", "Ambrose", "Amir", "Amon", "Andrew", "Angus", "Anthony", "Antonio", "Aristotle", "Arthur", "Ash", "Askeladd", "Astram", "Attila", "Atmere", "Austin", "Baam", "Barnaby", "Bartholomew", "Balthasar", "Beevor", "Bertram", "Benjamin", "Boris", "Bors", "Black", "Blake", "Bradley", "Brandon", "Brent", "Brian", "Brutus", "Bob", "Burton", "Caesar", "Cadogan", "Cador", "Cain", "Caius", "Caleb", "Caliban", "Camus", "Cameron", "Canute", "Carl", "Carlyle", "Caspian", "Cassius", "Cedric", "Chad", "Charles", "Christopher", "Claude", "Claudius", "Colt", "Connie", "Connor", "Cornelius", "Cuthbert", "Dalinar", "Damian", "Daniel", "Devon", "Daryl", "David", "Declan", "Derek", "Deez", "Diego", "Dietrich", "Dominic", "Donovan", "Drake", "Dustin", "Deandre", "Deshawn", "Dwayne", "Dylan", "Edward", "Edgar", "Egbert", "Egg", "Elbert", "Eldigan", "Elijah", "Elliot", "Elodin", "Elwyn", "Emile", "Emmanuel", "Eric", "Ethan", "Etzel", "Ezekiel", "Ezra", "Fabian", "Falco", "Fang", "Faust", "Felix", "Fenris", "Ferdinand", "Ferguson", "Finley", "Finn", "Fisher", "Fitzgerald", "Fox", "Francis", "Franklin", "Fraser", "Frederick", "Friedrich", "Fritz", "Gabriel", "Gaius", "Gaheris", "Galahad", "Gareth", "Garret", "Gavin", "Gawain", "George", "Gerald", "Gil", "Gilbert", "Giovania", "Grant", "Graham", "Gregor", "Gregory", "Grim", "Grit", "Gunther", "Hal", "Hamilton", "Hamish", "Hamlet", "Hank", "Hannibal", "Hans", "Harley", "Harry", "Harold", "Harvey", "Havelock", "Havel", "Hawk", "Hayes", "Heathcliff", "Herbert", "Hermes", "Hershel", "Henry", "Homer", "Horatio", "Howl", "Hubert", "Huey", "Hugh", "Hugo", "Humphrey", "Hutch", "Iago", "Ian", "Icarus", "Igor", "Ike", "Isaac", "Isaiah", "Ivan", "Jack", "Jacob", "Jacques", "James", "Jason", "Jay", "Jean", "Jenova", "Jamaal", "Jeffrey", "Jegran", "John", "Jonathan", "Joseph", "Joshua", "Jovanni", "Julian", "Julius", "Kaius", "Kaladin", "Keith", "Kelsier", "Kent", "Kenneth", "Kevin", "Kieran", "Kirbles", "Kirk", "Kyle", "Laius", "Lance", "Lancelot", "Landrick", "Lamorak", "Lawrence", "Layle", "Layton", "Lee", "Leo", "Leonardo", "Lewis", "Liam", "Lloyd", "Logan", "Ludwig", "Luke", "Luther", "Maes", "Malachi", "Malcolm", "Manfred", "Marco", "Marcus", "Martin", "Marquise", "Mark", "Mason", "Matthew", "Max", "Maximillian", "Maximus", "Merlin", "Micah", "Michael", "Michalis", "Milo", "Mordred", "Morien", "Mustang", "Nathan", "Neil", "Neville", "Nicholas", "Nikolai", "Noah", "Oberon", "Octavian", "Odysseus", "Oliver", "Orlando", "Orpheus", "Orsino", "Osborne", "Oscar", "Oswald", "Othello", "Otto", "Owen", "Parker", "Pascal", "Patrick", "Pedro", "Percival", "Peter", "Philip", "Pierro", "Plato", "Prospero", "Pyron", "Quan", "Quake", "Quentin", "Quenton", "Ragnar", "Ralph", "Randolf", "Remus", "Ricardo", "Rickard", "Richard", "Robert", "Robin", "Romeo", "Romulus", "Ronald", "Ross", "Rowan", "Roy", "Rupert", "Ryan", "Ryude", "Samson", "Samuel", "Scar", "Scott", "Sean", "Sebastian", "Selim", "Sergei", "Seth", "Shem", "Shylock", "Siegfried", "Siegmund", "Sigurd", "Simon", "Socrates", "Sokka", "Solomon", "Solaire", "Sorin", "Stanley", "Stephen", "Stuart", "Storm", "Sullivan", "Sven", "Swift", "Sylvester", "Taborlin", "Tarsus", "Terrance", "Terrell", "Thaddeus", "Theodore", "Theophilus", "Thiago", "Thomas", "Thor", "Thorn", "Trayvon", "Tidus", "Timothy", "Trevor", "Tristan", "Tyler", "Tyrone", "Ulysses", "Ulrich", "Urban", "Uther", "Valentine", "Victor", "Vincent", "Virgil", "Vlad", "Volke", "Vulcan", "Vyland", "Wade", "Wallace", "Walter", "Watson", "Wesley", "White", "Will", "William", "Wilhelm", "Wilson", "Winfred", "Winston", "Wolfram", "Woodrow", "Xander", "Xerxes", "Xavier", "Ywain", "Zachary", "Zephyr", "Zuko" };

Masculine ^^

return { "Abigail", "Ada", "Alexandra", "Alice", "Alvida", "Ann", "Anna", "Anne", "April", "Ari", "Ariel", "Auri", "Ayra", "Azula", "Azura", "Beatrice", "Berta", "Beth", "Bianca", "Blanche", "Calypso", "Cassandra", "Catherine", "Catria", "Celia", "Charlotte", "Connie", "Cynthia", "Dana", "Denna", "Deirdre", "Devi", "Diana", "Dorothy", "Eleanor", "Emily", "Emma", "Erin", "Esther", "Ethel", "Ethlyn", "Eva", "Eve", "Farlyn", "Finley", "Francesca", "Gabriella", "Gael", "Gemma", "Gertrude", "Giana", "Gillian", "Giovanna", "Gloria", "Grace", "Gretchen", "Gretel", "Hannah", "Hecate", "Helen", "Helena", "Hillary", "Holly", "Inari", "Iris", "Isabella", "Jane", "Jennifer", "Jemima", "Jess", "Jessie", "Jessica", "Joan", "Joanna", "Juliet", "July", "June", "Katara", "Katarina", "Kate", "Katie", "Katherine", "Kay", "Kayleigh", "Korra", "Lachesis", "Lomberta", "Lotte", "Lena", "Lucile", "Marceline", "Marcille", "Margaret", "Maria", "Maude", "May", "Mia", "Midir", "Miranda", "Morgan", "Nia", "Norne", "November", "Nyna", "Olivia", "Ophelia", "Palla", "Patricia", "Penny", "Quinn", "Rachel", "Rebecca", "Robin", "Rose", "Ruby", "Sabrina", "Saffron", "Samantha", "Sandra", "Sarah", "Sashenka", "Satu", "Serena", "Sidura", "Silvia", "Solara", "Solveig", "Sylvia", "Sophie", "Susanna", "Tabitha", "Taliah", "Tallulah", "Tami", "Tanya", "Tatiana", "Taylor", "Thalassa", "Theodora", "Theresa", "Titania", "Toph", "Tracey", "Ulla", "Uma", "Ursa", "Ursula", "Usha", "Valda", "Valencia", "Valentina", "Valerie", "Vanessa", "Vega", "Victoria", "Viola", "Violet", "Vivian", "Wendelin", "Wendy", "White", "Whitney", "Willa", "Winnie", "Xena", "Yara", "Yana", "Yvette", "Zemora", "Zoe", "Zoey" };

Feminine ^^

The if block responsible for setting v2 never ran which is why it stayed nil. This is a problem with the parameter, go check and see if the Male input is actually a Boolean

Okay I made sure its a boolean but im getting a new error
image

local Name = Instance.new("StringValue",folder)
	Name.Name = "CharName"

the error occurs on this line

NameValue.Value = NameData:GetAsync(plr.UserId) or "None"
local NameValue = Name
	NameValue.Value = NameData:GetAsync(plr.UserId) or "None"
	NameData:SetAsync(plr.UserId, NameValue.Value)
	
	NameValue.Changed:Connect(function()
		NameData:SetAsync(plr.UserId,NameValue.Value)
	end)
	

Have you tried using tostring(userId)?

try print(NameData:GetAsync(plr.UserId)) and see what value you are getting

Could you show the part of the code where you called the module.FirstName function

local v2

if Male then
	v2 = MasculineNames
else
	v2 = FeminineNames
end

return v2[math.random(1,#v2)]

The statement elseif Male == false will evaluate to false if ‘Male’ is nil. ‘nil’ is falsy in Lua/Luau but it is not equal to ‘false’.