I am working on a round system and after the intermission that I made I want it so that the map from replicated storage will spawn in and teleport all the players in DIFFERENT locations so that they all don’t spawn in the same place and all kill fight right when they spawn in. Any way I can do this?
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Map = RS:WaitForChild("MAP_HERE")
local Spawns = Map:FindFirstChild("SpawnBricks"):GetChildren()
local AvailableSpawns = {}
local NewMap = Map:Clone()
for _, Brick in ipairs(Spawns) do
if Brick:IsA("BasePart") then
table.insert(AvailableSpawns, Brick)
end
end
NewMap.Parent = workspace
for _, Player in pairs(Players:GetPlayers()) do
local Character = Player.Character or Player.CharacterAdded:Wait()
if #AvailableSpawns > 0 then
local SpawnIndex = math.random(1, #AvailableSpawns)
local PlayerSpawn = AvailableSpawns[SpawnIndex]
table.remove(AvailableSpawns, SpawnIndex)
Character:WaitForChild("HumanoidRootPart").CFrame = PlayerSpawn.CFrame
end
end
Make sure to change MAP_HERE to your actual map name, And make sure to have a folder with your spawn positions in it just like in this screenshot
2 Likes
I tested recently and when people spawn in sometimes they spawn in the same spot, I did not change anything else in the script you gave me.
local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local RoundSystem = PlayerGui:WaitForChild("RoundSystem")
local Status = RoundSystem:WaitForChild("Container"):WaitForChild("Status")
local TweenService = game:GetService("TweenService")
local TimerText = RoundSystem:WaitForChild("Timer"):WaitForChild("RoundTimer"):WaitForChild("Clock")
local Container = RoundSystem:WaitForChild("Container")
local Timer = RoundSystem:WaitForChild("Timer")
local Starting = false
local RS = game:GetService("ReplicatedStorage")
local Map = RS:WaitForChild("ClassicMap")
local Spawns = Map:FindFirstChild("SpawnParts"):GetChildren()
local AvailableSpawns = {}
local NewMap = Map:Clone()
local function Intermission()
if Starting then
local PlayerCount = #game.Players:GetPlayers()
TweenService:Create(Timer, TweenInfo.new(1.3, Enum.EasingStyle.Exponential), {Position = UDim2.fromScale(0.5, 0.020)}):Play()
if PlayerCount < 2 then
Starting = false
TweenService:Create(Timer, TweenInfo.new(1.3, Enum.EasingStyle.Exponential), {Position = UDim2.fromScale(0.5, -0.25)}):Play()
else
for i = 20,0,-1 do
TimerText.Text = i
task.wait(1)
end
for _, Brick in ipairs(Spawns) do
if Brick:IsA("BasePart") then
table.insert(AvailableSpawns, Brick)
end
end
NewMap.Parent = workspace
for _, Player in pairs(Players:GetPlayers()) do
local Character = Player.Character or Player.CharacterAdded:Wait()
if #AvailableSpawns > 0 then
local SpawnIndex = math.random(1, #AvailableSpawns)
local PlayerSpawn = AvailableSpawns[SpawnIndex]
table.remove(AvailableSpawns, SpawnIndex)
Character:WaitForChild("HumanoidRootPart").CFrame = PlayerSpawn.CFrame
for i = 60,0,-1 do
TimerText.Text = i
task.wait(1)
end
end
end
end
end
end
local function UpdateStatus()
local PlayerCount = #game.Players:GetPlayers()
print("There are " .. PlayerCount .. " players in game.")
if PlayerCount < 2 then
Status.Text = "Need 2 or more players to start"
Starting = false
TweenService:Create(Timer, TweenInfo.new(1.3, Enum.EasingStyle.Exponential), {Position = UDim2.fromScale(0.5, -0.25)}):Play()
task.wait(2)
Container.BackgroundTransparency = 0.3
Status.TextTransparency = 0
TweenService:Create(Container, TweenInfo.new(1, Enum.EasingStyle.Exponential), {Position = UDim2.fromScale(0.5, 0)}):Play()
elseif not Starting then
task.wait(2)
TweenService:Create(Container, TweenInfo.new(1, Enum.EasingStyle.Exponential), {Position = UDim2.fromScale(0.5, -0.3)}):Play()
task.wait(1)
Container.BackgroundTransparency = 1
Status.TextTransparency = 1
Starting = true
Intermission()
end
end
Players.PlayerAdded:Connect(UpdateStatus)
Players.PlayerRemoving:Connect(UpdateStatus)
UpdateStatus()
might be bc i made it a spawn part and not a “part”
integrate something like this into ur script, it should help (youll need to premake each spawner with numbers 1 up to the player limit for this to work):
local picked = {}
local chosen
function spawning()
for i, v in pairs(game.Players:GetPlayers()) do
repeat
chosen = math.random(1,#game.Players:GetPlayers())
until not table.find(picked,chosen)
picked[chosen] = chosen
v.Character:WaitForChild("HumanoidRootPart").CFrame = (folder)[chosen].CFrame + Vector3.new(0,2,0)
end
end
^^^ also please make sure to use regular parts for this!!!
1 Like