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

Why can't my script get the position of an object?

Asked by 6 years ago
Edited 6 years ago

In this PART OF A SCRIPT, I want a zombie to teleport to one of the random 6 Spawning positions in the map. Btw i'm holding the positions in a table. The positions are in workspace in a folder (Map) in a model called Field.

zombie1.UpperTorso.CFrame = game:GetService("Workspace").Map.Field:WaitForChild(ZombieTable
[math.random(1,6)].CFrame) --ONE LINE, JUST RAN OUT OF SPACE!

It says:

argument missing or nil

on the line of code. Any help would be appreciated.

0
What is ZombieTable? Is it a table of parts or a table of CFrames? chomboghai 2044 — 6y
0
Part. I probably should make it CFrames though... kittonlover101 201 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

If the ZombieTable is a table of Vector3Values, you must firstly use .Value to get their value, and secondly put the value inside a CFrame.new(), rather than getting the .CFrame of a Vector3 (which doesn't exist).

However, if the table is of parts that represent the positions, which it most likely is, you are using WaitForChild wrong. WaitForChild takes a string, and you are giving it the CFrame of the part instead. To solve this, you can change it to something like the following, without a WaitForChild:

local ZombieTable = workspace.Map.Field:GetChildren()
local ChosenCFrame = ZombieTable[math.random(#ZombieTable)].CFrame
zombie1.UpperTorso.CFrame = ChosenCFrame

Make sure the Field map only contains BaseParts.

0
Why is ZombieTable the map? The table is like a real table. Not a map? kittonlover101 201 — 6y
0
Good point, I forgot to add the :GetChildren(). Edited now. mattscy 3725 — 6y
Ad

Answer this question