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

How can I teleport players to a map with the most votes?

Based on this information about my game, can someone tell me how to teleport ALL players in the game to the map that has been voted for the most?

My intermission client script: (Local Script)

local playersFrame = script.Parent:WaitForChild("PlayersFrame")
local rStorage = game:GetService("ReplicatedStorage")
local rEvents = rStorage:WaitForChild("RemoteEvents")
local configs = rStorage:WaitForChild("Configs")
local interText = script.Parent:WaitForChild("Intermission Text")
local voteFrame = script.Parent:WaitForChild("VoteFrame")

local curVote

rEvents.AddPlayer.OnClientEvent:Connect(function(plr)
	local image = Instance.new("ImageLabel",playersFrame)
	image.Name = plr.UserId
	image.BorderSizePixel = 0
	image.BackgroundTransparency = .65
	image.BackgroundColor3 = Color3.fromRGB(0,0,0)
	image.Image = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420)
end)

rEvents.RemovePlayer.OnClientEvent:Connect(function(plr)
	local image = playersFrame:FindFirstChild(plr.UserId)
	if image then
		image:Destroy()
	end
end)

rEvents.RemoveAllVotes.OnClientEvent:Connect(function()
	for i,v in pairs(voteFrame:GetChildren()) do
		if v.Name == "%Grid%" then
			
		else
			v:Destroy()
		end
	end
end)

rEvents.CreateVote.OnClientEvent:Connect(function(name,imageId)
	local image = Instance.new("ImageButton",voteFrame)
	image.Name = name
	image.BorderSizePixel = 0
	image.BackgroundTransparency = .65
	image.BackgroundColor3 = Color3.fromRGB(0,0,0)
	image.Image = "rbxassetid://".. imageId
	
	image.MouseButton1Click:Connect(function()
		if curVote == image then
			
		else
			if curVote == nil then
			else
				rEvents.RemoveVote:FireServer(curVote.Name)
			end
			
			curVote = image
			rEvents.AddVote:FireServer(name)
		end
	end)
end)

configs.Status:GetPropertyChangedSignal("Value"):Connect(function()
	interText.Text = configs.Status.Value
end)

--My intermission is shown on a GUI, like in the game Piggy, a popular ROBLOX game by MiniToon.

Game handler script: (Server Script)

local rStorage = game:GetService("ReplicatedStorage")
local rEvents = rStorage:WaitForChild("RemoteEvents")
local configs = rStorage:WaitForChild("Configs")
local maps = rStorage:WaitForChild("Maps")

rEvents.AddPlayer.OnServerEvent:Connect(function(plr)
	rEvents.AddPlayer:FireAllClients(plr)
end)

rEvents.RemovePlayer.OnServerEvent:Connect(function(plr)
	rEvents.RemovePlayer:FireAllClients(plr)
end)

rEvents.AddVote.OnServerEvent:Connect(function(plr,name)
	local map = rStorage.Votes:FindFirstChild(name)
	if map then
		map.Value = map.Value + 1
	end
end)

rEvents.RemoveVote.OnServerEvent:Connect(function(plr,name)
	local map = rStorage.Votes:FindFirstChild(name)
	if map then
		map.Value = map.Value - 1
	end
end)

while true do
	local timer = 15
	repeat wait()
		configs.Status.Value = "Intermission: ".. timer
		
		wait(1)
		timer = timer - 1
	until timer == 0
	configs.Status.Value = "..."
	wait(1)
	
	for i,v in pairs(maps:GetChildren()) do
		local voteId = v:FindFirstChild("VoteId")
		if voteId then
			local intValue = Instance.new("IntValue",rStorage.Votes)
			intValue.Name = v.Name
			intValue.Value = 0
			
			rEvents.CreateVote:FireAllClients(v.Name,voteId.Value)
		end
	end
	
	timer = 10
	repeat wait()
		configs.Status.Value = "Map vote: ".. timer
		
		wait(1)
		timer = timer - 1
	until timer == 0
	configs.Status.Value = "..."
	
	local map
	local highest = 0
	for i,v in pairs(rStorage.Votes:GetChildren()) do
		if v:IsA("IntValue") then
			local curMap = maps:FindFirstChild(v.Name)
			if v.Value > highest and curMap then
				map = curMap
			end
		end
	end
	
	if map then
		configs.Status.Value = map.Name
	else
		map = maps:GetChildren()[1]
		configs.Status.Value = map.Name
	end
	
	rEvents.RemoveAllVotes:FireAllClients()
	
	for i,v in pairs(rStorage.Votes:GetChildren()) do
		v:Destroy()
	end
	
	wait(3)
	
	wait()
end

I have my maps stored in Replicated Storage in a folder, and based on these scripts, can someone suggest a way to teleport players to the map that was voted for the most by creating a new variable called 'ChosenMap' or something like that? Also please tell me if I need to do this in a new script or in one of these shown above. Thank you.

1 answer

✓ Accepted answer

Put this in a server script. It will loop through all the players and teleport them to a specific destination.

for _, v in pairs(game.Players:GetPlayers()) do
	v.Character.HumanoidRootPart.CFrame = --Your map part
end

On the comment about Map part, I realised you have an array. My advise would be to put the map parts, along with the spawn CFrame.

local Dictionary = {
	Map1 = Map1.CFrame
	Map2 = Map2.CFrame
	--etc.
}

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