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

I need help with a table?

I'm making a spawning script that uses a table but I don't know how to use a table other then typing in the what the table will have in it like

local NPC = {"NPC1", "NPC2"}

that's all I know how to do with a table but I want to select a citizen from the table in this script


--1337Zombiegamer--
local SpawnPool = {"Citizen", "Citizen1", "Citizen2", "Citizen3"}
local NPC = game.Lighting.Citizen

while true do
local NPCCopy = NPC:Clone()
NPCCopy.Parent = Workspace
wait(30)
end

using math.random to spawn it in to the world from the lighting

2 answers

✓ Accepted answer
Citizen = --Directory here
Citizen 1 = --Directory here
--and over until u got all of them
Citizens = {Citizen, Citezen 1, etc, etc}

while wait() do
	RCitizen = Citizens[math.random(1, #Citizens)] --1 is how many are picked
	CRCitizen = RCitizen:clone()
	CRCitizen.Parent = game.Workspace
	wait(30)
end

8 comments

1

What do you mean by directory here? like the {"Citizen", "Citizen1", "Citizen2"} part?

1

I'm kinda confused considering how you wrote the script..

1

Directory I mean is... Citizen = game.Lighting.blablabla u get the point?

1

Okay I edited the script there we're a few things misspelled but now in the output i get a error and nothing spawns in -- 12:59:55.648 - Workspace.CitizenSpawn:7: attempt to call method 'Clone' (a nil value)

1

are the citizens named Citizen 1, Citizen 2 etc?

1

nvm I fixed it

1

cool. cos I tried. they spawned for me... Glad to Help! :D thnx for Rating Boost, NOOBS keep putting it Down

1

also sry, I accidentally told u to Parent a Random Citizen to the Workspace, meaning, removing it from Lighting... I edited my Answer if it'll Help ;)

You see here

local NPC = {"NPC1", "NPC2"}

In order to fetch these you have to do "Where it's located"[1] or [2]. The way that tables work is in order so for example

local Bricks = {"Brick1", "Brick2"}

Workspace.Bricks[1]:Clone().Parent = Workspace.Model -- Clones Brick1
Workspace.Bricks[2]:Clone().Parent = Workspace.Model -- Clones Brick2

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