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

Scripting A Battle Royale Map?

local oldMessage = ""
local minPlayers = 2
 
function teleportAllPlayers()
    local target = CFrame.new(workspace.TeleportTarget.Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 1
        --add an offset of 5 for each character
    end
end
 
function message(message)
    if oldMessage ~= message then
        oldMessage = message
        print(message)
    end
end
 
function playersCurrentlyPlaying()
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.Playing.Value == 1 then return true end
    end
    return false
end
 
game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            player.Playing.Value = 0
        end)
    end)
 
    local playing = Instance.new("IntValue", player)
    playing.Value = 0
    playing.Name = "Playing"
end)
 
 
while(true) do
    wait(10)
    if #game.Players:getPlayers() >= minPlayers then
        if playersCurrentlyPlaying() then
            message("Waiting for the current game to end...")
        else
            message("There are enough players for a new game!  Teleporting...")
            wait(4)
            teleportAllPlayers()
        end
    else message("Waiting for more players...") end
end

This is what i have so far it teleports the players in but i need to find a way to make it so that it teleports the survivor back when theyre the last alive, And also i need a way to make it so that it prints who won and When the game is currently going if anyone can edit this script or tell me where and what to add or even has a script for a battle royale that will already do what i said that'd be really helpful and id appreciate it thanks. Also Need to find a way to make it reset the map when the games over

1 answer

This is from a script in an old game I was workin on a while ago. I don't know if this will work for you but worth a shot.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local status = ReplicatedStorage:WaitForChild('InfoValue')
local mapstorage = game.Workspace:WaitForChild('mapStorage')
local lobby = game.Workspace.Lobby
local GamePassService = game:GetService('GamePassService')
local GamePassIdObject = script:WaitForChild('GamePassId')
local Map1 = game.ServerStorage.Map1
local Map2 = game.ServerStorage.Map2
local Map3 = game.ServerStorage.Map3
local Map4 = game.ServerStorage.Map4


while true do
	while game.Players.NumPlayers > 2 do
		status.Value = 'There needs to be 2 or more players to begin!'
		repeat wait(2) until game.Players.NumPlayers >= 2
	end
	
	for i = 15,0,-1 do
		status.Value = 'Starting new round: '..i
		wait(1)
	end
		
	_G.gameplayers = {}
	
	for i,v in pairs(game.Players:GetPlayers()) do
		if v then
			table.insert(_G.gameplayers, v.Name)
			end
		end
	local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
	local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)]
	chosenmap:Clone().Parent = mapstorage
	status.Value = 'Get ready to be teleported!'
	wait(2)
	if chosenmap == Map1 then
		local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
	for _, player in pairs(game.Players:GetPlayers()) do
		if player and #spawns > 0 then
			local Torso = player.Character:WaitForChild('Torso')
			local allspawns = math.random(1,#spawns)
			local randomspawn = spawns[allspawns]
			if randomspawn and Torso then
				table.remove(spawns,allspawns)
				Torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
				end
			end
		end
	end	
		
	if chosenmap == Map2 then
		local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
	for _, player in pairs(game.Players:GetPlayers()) do
		if player and #spawns > 0 then
			local Torso = player.Character:WaitForChild('Torso')
			local allspawns = math.random(1,#spawns)
			local randomspawn = spawns[allspawns]
			if randomspawn and Torso then
				table.remove(spawns,allspawns)
				Torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))		
				end
			end
		end
	end
	if chosenmap == Map3 then
		local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
	for _, player in pairs(game.Players:GetPlayers()) do
		if player and #spawns > 0 then
			local Torso = player.Character:WaitForChild('Torso')
			local allspawns = math.random(1,#spawns)
			local randomspawn = spawns[allspawns]
			if randomspawn and Torso then
				table.remove(spawns,allspawns)
				Torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
				end
			end
		end
	end
	if chosenmap == Map4 then
		local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
	for _, player in pairs(game.Players:GetPlayers()) do
		if player and #spawns > 0 then
			local Torso = player.Character:WaitForChild('Torso')
			local allspawns = math.random(1,#spawns)
			local randomspawn = spawns[allspawns]
			if randomspawn and Torso then
				table.remove(spawns,allspawns)
				Torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))		
				end
			end
		end
	end
	
	
	
	
	for i = 120,0,-1 do
		if i == 0 then
			status.Value = 'Time up!'
			break
		end		
		wait(1)
		if #_G.gameplayers == 1 then
			for i,v in pairs(_G.gameplayers) do
				if v ~= nil then
					status.Value = v..' is the winner!'
					game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 50
					game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1
					break
				end
			end
			break
		else
			status.Value = i..' seconds remaining!'
		end
	end
	
	
	mapstorage:ClearAllChildren()
	local player = game.Players.LocalPlayer
	player.Backpack:ClearAllChildren()
	wait(5)
end

3 comments

0

Do i put the maps in server storage? do they need to be called a certain thing and Can i choose where they spawn?

0

That is just the script I use, you can always just tweak it to what you are using in your game. For example you can switch the map variables to look in game.Lighting.

0

Curious i used a terrain for my maps base cause i thought the new one looked more realistic how could i get it to include that with the map?

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