What do you want to achieve? Keep it simple and clear!
Script that makes all NPCs inserted have a random name. (Swears and mean words excluded)
What is the issue? Include screenshots / videos if possible!
I don’t have any screenshots or videos, but I am needing help finding a working and up to date script that makes NPCs in game have a random name.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Haven’t found or tried any solutions yet, found some topics to look through. Still can’t find a good looking script for what I need to achieve.
Do not DM me via profile, only @ me in messages so I can find your message. (Imagine I had like 500 Private Messages, it would be alot to scroll through).
@ Me if this is in the wrong category, I don’t know how to move topics so I will delete it, no category for this type of script? Doesn’t exist? I’ll also remove the topic.
You would have to have a list including every single name that you want to include. For that reason, there’s not an easy way for anybody to make one perfect script for this situation.
It would be random, so maybe this doesn’t exist.
I’m planning on having 10 NPCs with these names then:
NPC 1 would be named Berry
NPC 2 would be named Pondies
NPC 3 would be named Rann
NPC 4 would be named Roses
NPC 5 would be named Rocut
NPC 6 would be named Barryson
NPC 7 would be named Mecho
NPC 8 would be named Burger
NCP 9 would be named Lowtoe
NPC 10 would be named Robotic
Do these names follow the Roblox Terms of Service?
An easy way to do this is first to create an array of the names you want:
local Names = {“Bill”,”Ted”,”Mary”,”James”,”Ashlyn”}
You can put as many names in here as you want. After that, simply check when an NPC is added and give them a name.
local CharacterFolder = workspace:FindFirstChild(“NPCs”) — or wherever you insert them.
CharacterFolder.ChildAdded:Connect(function(NewCharacter)
NewCharacter.Name = Names[math.random(1,#Names)
end)
I’m on mobile so sorry for the formatting or any syntax errors.
Then, you just need to use the math namespace with it’s random function to choose one out of all possible entries, which you can do like this:
local randomName = names[math.random(#names)]
What you do here is, you try to index in the names table a index which you get randomly via math.random(). We supply this function with 1 argument, which is the amount of entries in the table, and this can be done by putting a # before the table name.
For more information about tables and what you can do with them, check the Developer Wiki for Tables.
local names = {
"Berry",
"Pondies",
"Rann",
"Roses",
"Rocut",
"Barryson",
"Mecho",
"Burger",
"Lowtoe",
"Robotic"
}
local function getRandomName()
return Names[math.random(#Names)]
end
local name = getRandomName()
print("Name:", name)
This would print out one of the 10 names in the names table.
The problem with this is that it doesn’t account for picking the same name twice. With a simple edit, you can make sure each name is only chosen once:
local function getRandomName()
local chosenIndex = math.random(1, #Names)
local chosenName = Names[chosenIndex]
table.remove(Names, chosenIndex)
return chosenName
end