Heyo,
i’m trying to make an intermission system. So during the intermission, the map will load, and thr players will be split up in these different teams (Note that some teams contains only 1 people (marked with a *)) :
Guard
D-Class
Scientist
SCP-106*
SCP-049*
SCP-745*
SCP-457*
SCP-939*
is there any ways to make this kind of repartition? I started a quick script :
local inter = game.ReplicatedStorage.Intermission.Intermission.Value
local bc = game.ReplicatedStorage.Intermission.backupCalled.Value
local bs = game.StarterGui.Intermission.Frame
function interMission()
if inter == true then
bs.Visible = true
wait(30)
-- Split up people here
end
end
Why do you need to do it with a constraint? Are you trying to teleport the players? If so, you can just loop through them and use this to teleport them somewhere:
local teleportLocation = Vector3.new(0,0,0)
for _,player in ipairs(Players) do
spawn(function()
local character = player.Character or player.CharacterAdded:Wait()
character:SetPrimaryPartCFrame(CFrame.new(teleportLocation))
end)
end
local MinSCPs = 1
local MinGuards = 1
local MinDClass = 1
local MinScientist = 1
local MaxPlayers = {
Guard = "none";
D-Class = "none";
Scientist = "none";
SCP-106 = 1;
SCP-049 = 1;
SCP-745 = 1;
SCP-457 = 1;
SCP-939 = 1;
}
local Normies = {
Guard;
D-Class;
Scientist
}
local SCPS = {
SCP-106;
SCP-049;
SCP-745;
SCP-457;
SCP-939;
}
local minPlayers = {
Guard = 1;
D-Class = 1;
Scientist = 1;
}
local PlayerRandomizer = Random.new()
--then the split up code would be
local Players = game.Players:GetPlayers()
local Cloned = MaxPlayers--Clone the table
local CurrentSCPs = 0
--Get people on MinScps
local RepeatIndex = 0
repeat
RepeatIndex = RepeatIndex + 1
local TargetedScp = SCPS[PlayerRandomizer:NextNumber(1, #SCPS)]
local TargetedPlayer = Players[PlayerRandomizer:NextNumber(1, #Players)]
--Put Player on SCP team
Players[table.find(Players, TargetedPlayer)] = nil--Player already got assigned
if Cloned[TargetedScp] == 1 then--If it reached limit then remove it from cloned
Cloned[TargetedScp] == nil
end
CurrentSCPs = CurrentSCPs + 1
until MinSCPs == RepeatIndex
RepeatIndex = 0--Prepare to loop and get guards
repeat
RepeatIndex = RepeatIndex + 1
local TargetedPlayer = Players[PlayerRandomizer:NextNumber(1, #Players)]
--Change TargetedPlayer team
Players[table.find(Players, TargetedPlayer)] = nil--Remove person
until MinGuards == RepeatIndex
RepeatIndex = 0--Prepare to loop and get DClass
repeat
RepeatIndex = RepeatIndex + 1
local TargetedPlayer = Players[PlayerRandomizer:NextNumber(1, #Players)]
--Change TargetedPlayer team
Players[table.find(Players, TargetedPlayer)] = nil--Remove person
until MinDClass == RepeatIndex
RepeatIndex = 0--Prepare to loop and get Scientists
repeat
RepeatIndex = RepeatIndex + 1
local TargetedPlayer = Players[PlayerRandomizer:NextNumber(1, #Players)]
--Change TargetedPlayer team
Players[table.find(Players, TargetedPlayer)] = nil--Remove person
until MinScientist == RepeatIndex
for i,v in pairs(Players) do--Will loop through rest of players randomly
local TargetRole = Normies[PlayerRandomizer(1, 3)]
--Set Player Team Accordingly
Players[i] = nil--Remove Player
end
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local noLimitTeams = {
Teams.Guard,
Teams.DClass,
Teams.Scientist
}
local onePersonTeams = {
Teams["SCP-106"],
Teams["SCP-049"],
Teams["SCP-745"],
Teams["SCP-457"],
Teams["SCP-939"],
}
local plrsInOnePersonTeams = #onePersonTeams
local howManyNoLimitTeams = #noLimitTeams
local function assignTeams()
local plrs = Players:GetPlayers()
local howMany = #plrs
local rng = Random.new(os.clock())
for i, team in ipairs(onePersonTeams) do
if i > howMany then
return
end
local randInd = rng:NextInteger(i, howMany)
plrs[randInd].Team = team
plrs[randInd] = plrs[i]
end
local plrsLeft = howMany-plrsInOnePersonTeams
if plrsLeft == 0 then
return
end
local maxPlrsInOneTeam = math.ceil(plrsLeft/howManyNoLimitTeams)
for i = 1, plrsLeft do
local minInd = plrsInOnePersonTeams+i
local randInd = rng:NextInteger(minInd, howMany)
plrs[randInd].Team = noLimitTeams[math.ceil(i/maxPlrsInOneTeam)]
plrs[randInd] = plrs[minInd]
end
end