Current issue: Timer reaches 0:00 after 15 minutes. But nothing else happens… Players don’t get teamed and the map doesn’t load out.
Once the timer is done, the program below is next, before anything else in the loop.
So the issue seems to be in this bit of code:
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v ~= nil then
v.Team = game:GetService("Teams").Spectator
v:LoadCharacter()
wait()
end
end
Put a print inside of the if statment to see if it’s printing, this is called “print debugging”, it’s know wether the code is making it to a certain part or not, for instance here we wanna know if the code got inside of the if statment, if not there is a problem.
Show more the script? ther’es nothing wroking with the code, but making if v ~= nil? Wdym? Just do if
local players = game.Players:GetChildren()
if #players >= 1 then
end
Just to add to the previous comments, you mentioned that you suspected the issue to be in this section of code, why is that? Did you get an error message on one of these lines?
Well what players are telling, and from what I can see is that, once the battle is over, after 15 minutes. The timer is stuck at 0:00.
The layout goes like this:
Counts down from 15 minutes to 0
Once 0, teams all players to Spectator
wait(1)
Removes current map.
People say nothing happens after the timer reaches 0:00, meaning it must be the next thing; The teaming all players. Players don’t get teamed and the map doesn’t get removed.
I’ve also updated the bit of code, but not sure if this will be the solution.
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v ~= nil then
v.Team = game:GetService("Teams"):FindFirstChild("Spectator")
if v ~= nil then
v:LoadCharacter()
end
wait()
end
end
Honestly, I think your issue is elsewhere. There’s nothing wrong with the code segment you’re giving us. Try tracing it from the code that’s supposed to run when the timer hits 0 and see if you can figure out what’s stopping it.
As a sidenote, you don’t need to check if something “~= nil” - simply leaving the name in there is good enough. So in your code it would be something like:
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v then
v.Team = game:GetService("Teams"):FindFirstChild("Spectator")
v:LoadCharacter()
wait()
end
end
Which also, you don’t need to check if v exists again before calling :LoadCharacter(). If you already checked it once, the chances are very good that the player won’t stop existing before the code changes their team.
Furthermore, you don’t have to check ‘v’ at all. The for loop in this case will only get existing Player objects. Therefore the ‘if v then’ statement will always be true.
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
v.Team = game:GetService("Teams"):FindFirstChild("Spectator")
v:LoadCharacter()
wait()
end
Have you gotten any console errors in your output? If I remember correctly LoadCharacter() only works when the character doesn’t exist. Try deleting the characters then calling :LoadCharacter().
It is a yielding function. I suppose that could be stopping your script, although I doubt it. To circumvent that, you can just make a new thread for each character like so:
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
v.Team = game:GetService("Teams"):FindFirstChild("Spectator")
spawn(function()
v:LoadCharacter()
end)
end
I also removed the wait() at the end of the for loop as well, because it really isn’t necessary.