Teleporting to a random location on a map

This is part of a script to teleport a player to a random part in a folder depending on which map is chosen:

if map.Name == "Caves" then
					humanoidRootPart.CFrame = game.Workspace.CaveSLs[math.random(1,#game.Workspace.CaveSLs)].CFrame
				end
				
				if map.Name == "Harbour" then
					humanoidRootPart.CFrame = game.Workspace.HarbourSLs[math.random(1,#game.Workspace.HarbourSLs)].CFrame
				end
				
				if map.Name == "Magical Forest" then
					humanoidRootPart.CFrame = game.Workspace.ForestSLs[math.random(1,#game.Workspace.ForestSLs)].CFrame
				end

It’s pretty simple, but I get this error:

Probably some easy fix. Anyone mind providing me with an answer? Thanks! :slight_smile:

(I presume it’s something to do with the ForestSLs)].CFrame part)

Try

game.Workspace.ForestSLs[math.random(1,#game.Workspace.ForestSLs:GetChildren())]

or

game.Workspace.ForestSLs:getChildren()[math.random(1,#game.Workspace.ForestSLs:GetChildren())]

Since an instance is not a table.

1 Like

Your second suggestion worked when I added .CFrame to it. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.