Hello, me and 2 others are working on a new game! It is an obby based game inwhich 2-10 players will get teleported to an obby, the last to complete the obby/furthest away from winpad when the timer runs out will get eliminated, this will continue until there is 1 person left they will get a win, (and if you complete a map you get 25 coins). However there is an error, sometimes the player will not switch from lobby to obby team (and vice versa) meaning sometimes you wont go in when a new game starts and sometimes noone will get eliminated after a round. we are noob scripters so any help would help thanks! here is the full round system script, if you notice any bugs please say!
local sss = game:GetService("ServerScriptService");
local rs = game:GetService("ReplicatedStorage")
local ws = game:GetService("Workspace");
local ss = game:GetService("ServerStorage");
local mps = game:GetService("MarketplaceService");
local cm = Instance.new("Folder", workspace);
cm.Name = 'CurrentMap';
local maps = ss:WaitForChild('Maps'):GetChildren();
local events = rs:WaitForChild('Events');
local status = events:FindFirstChild('StatusChange');
local round = 1;
local Playing = {};
local Obby = {};
game.Players.PlayerAdded:Connect(function(plr)
table.insert(Playing, plr);
end);
events.GoAFK.OnServerEvent:Connect(function(p, b)
if (b == false) then
local Inside = false;
for _,plr in pairs(Playing) do
if (p.UserId == plr.UserId) then
Inside = true;
break;
end;
end;
if (not Inside) then
table.insert(Playing, p);
end;
elseif (b == true) then
for num,plr in pairs(Playing) do
if (p.UserId == plr.UserId) then
table.remove(Playing, num);
break;
end;
end;
end;
end);
game.Players.PlayerRemoving:Connect(function(plr)
for i, v in pairs(Obby) do
if v.Name == plr.Name then
table.remove(Obby, i);
break;
end;
end;
for i, v in pairs(Playing) do
if v.Name == plr.Name then
table.remove(Playing, i);
break;
end;
end;
end);
while (true) do
repeat
status:FireAllClients('Waiting for more players...');
wait(0.1);
until #Playing >= 2
local Cplaying = Playing --// prevention of going afk during round
for i=1, 10 do
status:FireAllClients('Intermission '.. 10-i ..'...');
wait(1);
end;
status:FireAllClients('Choosing a map.');
wait(1.5);
local num = math.random(1, #maps);
local map = maps[num];
local cmap = map:Clone();
maps = ss:WaitForChild('Maps'):GetChildren();
table.remove(maps, num);
cmap.Parent = workspace:FindFirstChild('CurrentMap');
status:FireAllClients('The map '.. cmap.Settings.MapName.Value ..' was chosen. ['.. cmap.Settings.Difficulty.Value ..']');
wait(4)
for i=1, 100 do
status:FireAllClients('Loading Map ('.. i ..'%)');
wait(0.05);
end;
if (round == 1) then
for i, v in pairs(Playing) do
table.insert(Obby, v);
end;
end;
status:FireAllClients('Get Ready!');
wait(2);
local start = false;
for _,v in pairs(Obby) do
v.Team = game.Teams.Obby;
v:LoadCharacter();
v.Character:FindFirstChild('Humanoid').WalkSpeed = 0;
wait();
spawn(function()
repeat
v.Character:FindFirstChild('Humanoid').WalkSpeed = 0;
wait();
until start == true;
end);
end;
for i=1, 3 do
status:FireAllClients(4-i);
wait(1);
end;
status:FireAllClients('Go!');
start = true;
for _,v in pairs(Obby) do
v:LoadCharacter();
v.Character:FindFirstChild('Humanoid').WalkSpeed = 16;
end;
local playersTouching = {};
cmap.Essentials.Finish.Touched:Connect(function(hit)
if (hit.Parent:FindFirstChild('Humanoid')) then
if (not playersTouching[hit.Parent.Name]) then
if (#game.Teams.Obby:GetPlayers() > 1) then
playersTouching[hit.Parent.Name] = true;
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent);
plr.Team = game.Teams.Lobby;
plr:LoadCharacter();
if (game.PrivateServerId == '' and game.PrivateServerOwnerId == 0) then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 25;
if (mps:UserOwnsGamePassAsync(plr.UserId, 8370990)) then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 25;
end;
end;
end;
end
end;
end);
for i=1, 150 do
status:FireAllClients(150-i);
if (#game.Teams.Obby:GetPlayers() == 1) then
if (#Obby > 1) then
for i, v in pairs(Obby) do
if (v.Name == game.Teams.Obby:GetPlayers()[1].Name) then
status:FireAllClients(v.Name ..' has been removed from the obby games!');
local NoObbiers = #Obby;
v.Team = game.Teams.Lobby;
v:LoadCharacter();
table.remove(Obby, i);
break;
else
status:FireAllClients('The game has ended...');
break;
end;
end;
end;
break;
elseif (i >= 150) then
local distances = {};
local farthestDist = 0;
local players = game.Teams.Obby:GetPlayers();
local playerToBeRemoved = nil;
for _,v in pairs(players) do
local mag = (v.Character.Torso.Position-cmap.Essentials.Finish.Position).Magnitude;
if (mag > farthestDist) then
farthestDist = mag;
playerToBeRemoved = v;
end;
end;
local plr = playerToBeRemoved;
for i, v in pairs(Obby) do
if (v.UserId == plr.UserId) then
table.remove(Obby, i);
break;
end;
end;
for int, p in pairs(players) do
if (plr.UserId == p.UserId) then
p.Team = game.Teams.Lobby;
p:LoadCharacter();
break;
end;
end;
break;
elseif (#game.Teams.Obby:GetPlayers() == 0) then
round = 1;
Obby = {};
break;
end;
wait(1);
end;
wait(2);
if (#Obby == 1) then
status:FireAllClients(Obby[1].Name ..' has won the obby games!');
if (Obby[1].Character) then
if (game.PrivateServerId == '' and game.PrivateServerOwnerId == 0) then
Obby[1].leaderstats.Wins.Value = Obby[1].leaderstats.Wins.Value + 1;
Obby[1].leaderstats.Coins.Value = Obby[1].leaderstats.Coins.Value + 25;
if (mps:UserOwnsGamePassAsync(Obby[1].UserId, 8370990)) then
Obby[1].leaderstats.Coins.Value = Obby[1].leaderstats.Coins.Value + 25;
end;
end
Obby[1].Team = game.Teams.Lobby;
Obby[1]:LoadCharacter();
end;
round = 1;
table.remove(Obby, 1);
elseif #Obby > 1 then
round = round + 1
for i, v in pairs(Obby) do
if (Obby[i]) then
if (Obby[i].Character) then
Obby[i].Team = game.Teams.Lobby;
Obby[i]:LoadCharacter();
end;
end;
end;
end;
cmap:Destroy();
wait(2);
end;
Thanks, v_Lzke

2 comments
You mean the script won't run in the right way or just error?
it runs just sometimes people dont switch teams (it happens every 10 mins or so)