Basically I have this tournament game that assigns a player's name to a specific number in a folder that includes a place rank [e.x. player1 goes with 1, player 2 goes with player 2, etc.] and I'm trying to randomize it in a way that's more efficient.
Here's the script:
local ss = game:GetService("ServerStorage")
local values = ss:WaitForChild("Values")
local ingame = values:WaitForChild("In-Game")
local display = ingame:WaitForChild("display")
local countdown = ingame:WaitForChild("countdown")
local players = ss:WaitForChild("Players")
local number = players:WaitForChild("Number")
local number1 = number:WaitForChild("1")
local number2 = number:WaitForChild("2")
local number3 = number:WaitForChild("3")
local number4 = number:WaitForChild("4")
local number5 = number:WaitForChild("5")
local number6 = number:WaitForChild("6")
local number7 = number:WaitForChild("7")
local number8 = number:WaitForChild("8")
local playerfolder = ss:WaitForChild("PlayerFolder")
local playercount = ss:WaitForChild("PlayerCount")
local assign = players:WaitForChild("Assign")
while true do
if playercount.Value >= 3 then
while true do
for i = 20,0,-1 do
display.Value = 'Welcome! The game will begin shortly. Time Left: '..i
wait(1)
end
end
wait(3)
local p1 = playerfolder:FindFirstChild("1")
local p2 = playerfolder:FindFirstChild("2")
local p3 = playerfolder:FindFirstChild("3")
local p4 = playerfolder:FindFirstChild("4")
local p5 = playerfolder:FindFirstChild("5")
local p6 = playerfolder:FindFirstChild("6")
local p7 = playerfolder:FindFirstChild("7")
local p8 = playerfolder:FindFirstChild("8")
if p1 then
math.randomseed(tick())
assign.Value =(math.random(1, math.random(1, 8)))
if assign.Value == 1 then
if number1.Value == "" then
number1.Value = p1.Value
elseif number1.Value ~= "" then
if number2.Value == "" then
number2.Value = p1.Value
elseif number2.Value ~= "" then
if number3.Value == "" then
number3.Value = p1.Value
elseif number3.Value ~= "" then
if number4.Value == "" then
number4.Value = p1.Value
elseif number4.Value ~= "" then
if number5.Value == "" then
number5.Value = p1.Value
elseif number5.Value ~= "" then
if number6.Value == "" then
number6.Value = p1.Value
elseif number6.Value ~= "" then
if number7.Value == "" then
number7.Value = p1.Value
elseif number7.Value ~= "" then
if number8.Value == "" then
number8.Value = p1.Value
else
display.Value = "Game is broken. Please rejoin."
end
end
end
end
end
end
end
end
end
end
else
display.Value = "Game does not have enough players. " .. 3 - playercount.Value .. " players needed."
end
wait()
end
This is the script that runs when a player joins:
local Players = game:GetService("Players")
local ss = game:GetService("ServerStorage")
local playerfolder = ss:WaitForChild("PlayerFolder")
local playercount = ss:WaitForChild("PlayerCount")
game.Players.PlayerAdded:connect(function(player)
playercount.Value = playercount.Value + 1
print(player.Name .. " has entered the game")
local playerval = Instance.new("StringValue")
playerval.Parent = playerfolder
playerval.Value = player.Name
wait(1)
playerval.Name = playercount.Value
local playingval = Instance.new("BoolValue")
playingval.Parent = playerval
playingval.Name = "Playing"
playingval.Value = false
end)
game.Players.PlayerRemoving:connect(function(player)
playercount.Value = playercount.Value - 1
print(player.Name .. " has left the game")
local pvalue = playerfolder:FindFirstChild(player.Name)
pvalue:Destroy()
end)
Screenshot of where everything is located: Explorer Screenshot
I know I have to use tables in a way, or figure out how to put players' names into a table, but how would I approach this so that the Number Folder will have player's names inside and randomized in order to start a game, and to do it efficiently? (Basically the Number's Value will correlate to a player's name (meaning the 1,2,3,4, etc. are StringValues.)
-Luke
