I've written this script for basically a round system for a game, but it just doesn't function.
while true do --begin loop
IntermissionTime = 30
a = game.Players:GetChildren()
x = 4 - #a
if #a < 4 then --check for numplayers
for i,v in pairs(a) do
v.PlayerGui.ScreenGui.Frame.RoundTime.Text = x.." more players are needed to start the round."
end
elseif #a >= 4 then
repeat --intermission timer run
wait(1)
for i,v in pairs(a) do --change playergui intermission text
IntermissionTime = IntermissionTime - 1
player.PlayerGui.ScreenGui.Frame.RoundTime.Text = "Intermission: "..IntermissionTime
end
until
IntermissionTime == 0
end
if IntermissionTime == 0 then --begin round
for i,v in pairs(a) do --change playergui text to round beginning
a.PlayerGui.ScreenGui.Frame.RoundTime.Text = "Round beginning!"
end
wait(5)
-- randomly choose 1 player
local players = {game.Players:GetChildren()}
local randomPlayer = math.random(1,#players)
randomPlayer.TeamColor = BrickColor.new("Bright red")
m = Instance.new("Message")
m.Parent = game.Workspace
m.Text = randomPlayer.." is the Juggernaut this round."
wait(5)
m:Destroy()
-- spawn random map
local maps = {"Map1", "Map2", "Map3", "Map4", "Map5"}
local randomMap = maps[math.random(1, #maps)]
clone = game.Lighting:FindFirstChild(randomMap):Clone()
clone.Parent = Game.Workspace -- Make sure to set the clones parent.
-- delete lobby spawnlocations
spawns = game.Workspace.Lobby:GetChildren()
for i,v in pairs(spawns) do --reparent spawnlocations
if v:IsA("SpawnLocation") then
v.Parent = game.Lighting
end
end
--spawn players
for i,v in pairs(a) do --kill players
v.Character:WaitForChild("Humanoid").Health = 0
end
--begin round timer
RoundTime = 300
repeat
wait(1)
for i,v in pairs(a) do
RoundTime = RoundTime - 1
a.PlayerGui.ScreenGui.Frame.RoundTime.Text = "Time Left: "..RoundTime
end
until
RoundTime == 0
if Roundtime == 0 then --round end
for i,v in pairs(a) do --change playergui
v.PlayerGui.ScreenGui.Frame.RoundTime.Text = "Round over!"
end
for i,v in pairs(game.Lighting:GetChildren()) do --reassign spawnlocation parents to workspace
if v:IsA("SpawnLocation") then
v.Parent = game.Workspace
end
end
for i,v in pairs(game.Workspace:GetChildren()) do --destroy map
if v.Name == "Map%d" then
v:Destroy()
end
end
for i,v in pairs(a) do
v.Character:WaitForChild("Humanoid").Health = 0
end
end --end roundend if statement
end --end round begin
end --end loop
I'd appreciate any help you guys can offer. Thanks!

1 comment
The problem is that it's not even starting from the beginning. It won't change the Gui like I wanted it to in the beginning.