How would i be able to start the script below when theres atleast 2 players in the game and also update the status bar with for example “1 more player needed to start”?.
local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()
while true do
for i = 1,15 do
status.Value = "Next round will start in: "..15-i
wait(1)
end
local rand = math.random(1, #maps)
local map = maps[rand]:Clone()
map.Parent = workspace
status.Value = "The next minigame is: "..map.Name
wait(5)
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
local spawnLocation = math.random(1,#map.Teleports:GetChildren())
players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLocation].Position)
players[i].Character.Parent = workspace.Ingame
end
end
local roundLenght = 60
local canWin = true
local roundType = ""
if map:FindFirstChild("Race") then
roundType = "Race"
map.WinnerPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
canWin = false
status.Value = hit.Parent.Name.." Has won!"
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value +100
end
end)
end
repeat
roundLenght = roundLenght -1
status.Value = "Time left: "..roundLenght
wait(1)
until roundLenght == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0
wait(3)
map:Destroy()
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i]:LoadCharacter()
end
end
end
This won’t work because it you try to get the length of game.Players and not the actual players. What OP has to do is:
local Players = game:GetService("Players")
repeat task.wait(1)
print("Waiting for players:", tostring(#Players:GetPlayers()).."/2")
until #Players:GetPlayers() >= 2
local counter = 0
Players.PlayerAdded:Connect(function(player)
counter += 1
if counter > 2 then
--Do whatever you want here (or use one of those funi remote event things to activate another script, or you can use otherscript.Disabled = false and have it set as disabled by default)
end
end)
btw put this in server script storage if I remember correctly
Did you literally just paste this into a script? because the part I commented out requires you to edit so it would actually start the original script in some ways.
For example, you could set your original script to “Disabled = true”, then add “game.Workspace.OriginalScript.Disabled = false” in the commented out area
local Rp = game:GetService("ReplicatedStorage")
local Status = Rp.Status
Status.Value = "Waiting For Players"
repeat task.wait() until #game.Players:GetPlayers() >= 2
if #game.Players:GetPlayers() >= 2 then
Status.Value = "Starting"
print("yes")
end
and then create a local script inside the textlabel and detect whenever the value changes if it changes then it will set the text to the StringValue’s Value.
LocalScript :
game.ReplicatedStorage.Status.Changed:Connect(function(Val)
script.Parent.Text = Val
end)