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

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

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.

2 comments

0

What is ZombieTable? Is it a table of parts or a table of CFrames?

0

Part. I probably should make it CFrames though...

1 answer

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.

2 comments

0

Why is ZombieTable the map? The table is like a real table. Not a map?

0

Good point, I forgot to add the :GetChildren(). Edited now.

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