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

Why doesn't my map changer teleport the players?

Here's the script:

local players = game.Players:GetChildren()
local maps = game.Lighting.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn")
local choices = {}

function chooseMap()
	for i = 1,#maps do
		if maps[i]:isA("Model") then
			table.insert(choices,maps[i])
		end
	end
	local picked = math.random(1,#maps)
	chosenmap.Value = choices[picked].Name
end

function loadMap()
	local map = game.Lighting.Maps:FindFirstChild(chosenmap.Value)
	map:Clone().Parent = currentmap
end

function deleteMap()
	for i,v in pairs(currentmap:GetChildren()) do
		if v:isA("Model") then
			v:Destroy()
		end
	end
end

function teleportPlayers()
	for i,v in pairs(players) do
		v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn*CFrame.new(math.random(5,10),0,math.random(5,10))
	end
end

while true do
	wait(3)
	chooseMap()
	loadMap()
	wait(1)
	teleportPlayers()
	wait(10)
	deleteMap()
	teleportPlayers()
end

There is a folder named CurrentMap, and a string value name "ChosenMap" inside the script, all of which is in the workspace.

The two maps are in a group called "Maps" and put into the lighting.

There aren't any spawn locations, just parts named spawn.

1 comment

0

Sorry it's pretty complicated

1 answer

function teleportPlayers()
    for i,v in pairs(players) do
        v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame*CFrame.new(math.random(5,10),0,math.random(5,10))
    end
end

Maybe? You forgot to take the CFrame of the spawn

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