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

Hey i made a map changer but i need help to make it teleport the players when the map loads?

local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("StatusValue")

while true do
    -- Intermission
    for i = 30, 0, -1 do
        status.Value = "Intermission: " .. i 
        wait(1) 
    end
    local map = game.ServerStorage.GlassMap
    map:Clone().Parent = workspace
    wait(15)
    map:Destroy()
    status.Value = "Game End"
end
--// For future reference, your code has to go in between two sets of tildes(~). You had an extra one messing it up.

I want it to teleport them to the map when the map loads and when the map destroys i want it to teleport them back to the lobby is that possible to fix?

2 comments

1

Please use code blocks. It is the Lua symbol at the top while editing.

0

You could edit the CFrame or position (position is probably better) of all the players in order to teleport them.

1 answer

players = game:GetService("Players")

 -- loop to get every player in the game
for _, player in pairs(players) do
	
	local character = player.Character
	
	--check if the player is not dead
	if character then
 		character:SetPrimaryPartCFrame(spawn_part.CFrame) 
		--you must create a variable for the spawn part
	end
end

So it would look like this:

local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("StatusValue")
players = game:GetService("Players")
lobby_spawn = game.Workspace.Spawn --change this to the lobby spawn/part 

while true do
    -- Intermission
    for i = 30, 0, -1 do
        status.Value = "Intermission: " .. i 
        wait(1) 
    end
    local map = game.ServerStorage.GlassMap
    map:Clone().Parent = workspace
	spawn_part = map.Spawn --insert a spawn/part named "Spawn" in the map model

	for _, player in pairs(players) do
	
		local character = player.Character
		if character then
	 		character:SetPrimaryPartCFrame(spawn_part.CFrame) 
		end
	end

    wait(15)

	for _, player in pairs(players) do
	
		local character = player.Character
		if character then
	 		character:SetPrimaryPartCFrame(lobby_spawn.CFrame) 
		end
	end
	
    map:Destroy()
    status.Value = "Game End"
end

this will teleport them to the map and then you just have to repeat the loop but using the lobby's spawn. Hope I helped!

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