Attempt to get length of a instance value

Hiya,

I’m trying to teleport a particular team onto their designated spawn points in a map, but I’m receiving an error - “attempt to get length of a instance value”. I’ve checked numerous forum posts on this matter, but it seems to be something beyond my understanding as I don’t notice any clear issues with the code.

As you can see, I’ve specifically stated in the game script to retrieve the children (which are parts) of the AgentSpawns folder:

local Map = game.Workspace.Map:FindFirstChildWhichIsA("Model")
	Round.TeleportPlayers(Contestants, ChosenMALWARE, Map.AgentSpawns:GetChildren())

My module script then provides the table of children for the folder thereof and randomly assigns a player to each one.

function module.TeleportPlayers(Players, AgentSpawns)
	local Players = game.Players:GetPlayers()
	local Map = game.Workspace.Map:FindFirstChildWhichIsA("Model")
	for i,v in pairs(Players) do
		if v.Team == game.Teams["MALWARE"] then
			v.Character.HumanoidRootPart.CFrame = Map.MALWARESpawn.CFrame + Vector3.new(0,5,0)
			print("MALWARE sent to their spawn")
		elseif v.Team == game.Teams["Agents"] then
			local Rand = Random.new()
			v.Character.HumanoidRootPart.CFrame = AgentSpawns[Rand:NextInteger(1, #AgentSpawns)].CFrame + Vector3.new(0,5,0)
			print("Agents sent to their spawns")
		end
	end
end

When the code is run, MALWARE is transported to their spawn, whereas Agents remain in the lobby, thus stopping the code.

Thanks for any advice.

I think your problem is that the TeleportPlayers function has 2 defined parameters, however you’re sending 3 arguments to it. If you make another parameter definition for ChosenMALWARE, it should work as intended. Or, maybe just get rid of that argument entirely, as it doesn’t look like you need it.

So instead of:

--//The ChosenMALWARE argument is taking over the AgentSpawns parameter in the function, so your agent spawns table is never used.
Round.TeleportPlayers(Contestants, ChosenMALWARE, Map.AgentSpawns:GetChildren())

Try,

	Round.TeleportPlayers(Contestants, Map.AgentSpawns:GetChildren())

1 Like