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

"Attempt to index field '?' (nil value)" [SOLVED]

Whenever I try to run the script, the output just says "ServerScriptService.Script:14: attempt to index field '?' (a nil value)" I don't know what's happening, because if I remove the CFrame, the output just says "expecting CFrame". Help?

local MapsLocation = ServerStorage:WaitForChild("Maps")
local plrs = {}
local GetMaps = MapsLocation:GetChildren()
local MapToAppear = GetMaps[math.random(1, #AVMaps)]
local MapCloned = MapToAppear:Clone()
MapCloned.Parent = game.Workspace
local SpawnBricks = MapCloned:FindFirstChild("Spawn")
local SpawnsToTeleport = SpawnBricks:GetChildren()
wait(3)
	for i, plr in pairs(plrs) do
		if plr then
			char = plr.Character
			if char then
				char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame
				table.remove(SpawnsToTeleport, 1)
			end

3 comments

0

try printing spawnstoteleport[1] and see what you get

0

Prints nil (already tried that earlier), but the problem is that if i remove the [1], it will give an error ("bad argument #3, expecting CFrame)

0

if its printing nil your table probably doesnt have anything in it, so obviously it cant get cframe information from nothing.

2 answers

It's because you are indexing an empty table, you have no value for the player in the table. local plrs = {} -- Empty table

for i, plr in pairs(plrs) do -- indexing empty table

char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame -- indexing nil value

1 comment

0

I didn't include some parts of the actual script as those are the most important. There is a table.insert, which redirects the player name to the table.

So, I discovered that I could use the variable SpawnsToTeleport, use it as a table and put the SpawnBricks variable in.

local MapsLocation = ServerStorage:WaitForChild("Maps")
local plrs = {}
local GetMaps = MapsLocation:GetChildren()
local MapToAppear = GetMaps[math.random(1, #AVMaps)]
local MapCloned = MapToAppear:Clone()
MapCloned.Parent = game.Workspace
local SpawnBricks = MapCloned:FindFirstChild("Spawn")
local SpawnsToTeleport = {SpawnBricks}
wait(3)
for i, plr in pairs(plrs) do
	if plr then
		char = plr.Character
		if char then
			char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame
			table.remove(SpawnsToTeleport, 1)
		end

It didn't give me the error again, so yay?

2 comments

0

SpawnsToTeleport[1].CFrame, Change to: CFrame.new(SpawnsToTeleport[1].CFrame.Position)

0

@yHasteeD, the script actually takes me to the position I want without having to type CFrame.new and CFrame.Position.

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