Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

I need help with a table?

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
3
Answered by
KAAK82 16
10 years ago
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
1
What do you mean by directory here? like the {"Citizen", "Citizen1", "Citizen2"} part? Prioxis 673 — 10y
1
I'm kinda confused considering how you wrote the script.. Prioxis 673 — 10y
1
Directory I mean is... Citizen = game.Lighting.blablabla u get the point? KAAK82 16 — 10y
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) Prioxis 673 — 10y
View all comments (4 more)
1
are the citizens named Citizen 1, Citizen 2 etc? KAAK82 16 — 10y
1
nvm I fixed it Prioxis 673 — 10y
1
cool. cos I tried. they spawned for me... Glad to Help! :D thnx for Rating Boost, NOOBS keep putting it Down KAAK82 16 — 10y
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 ;) KAAK82 16 — 10y
Ad
Log in to vote
3
Answered by 10 years ago

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

Answer this question