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.