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

Help! I can't teleport players, somehow the model for teleporting players is gone?

local status = game.ReplicatedStorage:FindFirstChild("statustext") --References status as "statustext" from replicated storage
local Maps = game.ReplicatedStorage.Maps:GetChildren() -- Grabs all of the maps inside the folder, since we're using GetChildren.

while true do -- Creates a loop
	for i = 1,20 do -- What we are doing is, 'i' will equal to 1, then count up to 20, it will add 1 to 'i' after each round of code inside the for loop.
		status.Value = "Intermission: "..20-i -- We're making a timer from 20 seconds down to 0.
		wait(1) -- We wait 1 second before we go again
	end -- you should know.
	
	local rand = math.random(1, #Maps) -- we assume that there is 1 map, and we'll randomize the maps.

	local map = Maps[rand]:Clone() --c clones a map of itself that is chosen
	map.Parent = workspace -- Changes the parent of the map itself to workspace.

	status.Value = "Map Loaded: "..map.Name -- We're making a string saying that the game loaded.
	wait(5) -- We wait 5 seconds before we go to the next script
	
	local players = game.Players:GetChildren() -- We get players.
	for i = 1,#players do -- Makes a for loop using players so that we can teleport them.
		if players[i].Character ~= nil then -- Checks if the player is not a character
			local spawnLocation = math.random(1,#workspace.Teleports:GetChildren()) -- Grabs all of the teleport points
			players[i].Character:MoveTo(workspace.Teleports:GetChildren()[spawnLocation].Position) -- Teleports all the players to a random part depending on how much you put.
		end -- you should know.
	end -- you should know.
end -- you should know.

^^ The current code that I find the error in.

19:29:51.122 - Teleports is not a valid member of Workspace

I'm not sure why I can't teleport players because when I testplay the game, teleport model is gone and it will consider that error, I dont know how to fix this, can anyone help me? Somebody is having the same issue and they tried cloning it, and it doesn't seem to work.

What it looks like without testplaying

What it looks like WITH testplaying

1 comment

0

Which line?

1 answer

I see your error. You were using the correct format until randoming the key! You have chosen a key but never found it in the table... For example; you needed to use Table[math.random(1, #Table)] But you have used math.random(1, #table)

local Spawns = workspace.Teleports:GetChildren()
local spawnLocation = Spawns[math.random(1,#Spawns)]

And about your error, if streaming is enabled, some parts do not load in as the player has to walk close to it. If that is not the case, then Teleports does not actually exist.

3 comments

0

" And about your error, if streaming is enabled, some parts do not load in as the player has to walk close to it. If that is not the case, then Teleports does not actually exist." I do not get this part, as I had the model in? Could you explain it a bit?

0

Okay, So streaming enabled is a property of workspace, by enabling it, you reduce lag but you need to be close to the part to actually see the part

0

I tried both, and NOTHING worked, I tested it, and it seems like after a few seconds teleports is deleted, the model teleports.

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