Just as the title says, the loop works until it hits the function, where it stops completely. Any way to keep this loop to running for other players whilst still sending all players through the function?
function Give(Player)
local Clone = GUI:Clone()
local TopBox = Player:WaitForChild("PlayerGui"):FindFirstChild("TopBox")
if TopBox == nil and script:GetAttribute("MinigameRunning") == false then
Clone.Parent = Player.PlayerGui
Prepare()
end
end
function respawn()
script:SetAttribute("MinigameRunning", false)
for i,v in pairs(game.Players:GetPlayers()) do
print(v)
local attr = v:GetAttribute("Score")
if attr then
v:SetAttribute("Score", nil)
v:LoadCharacter()
end
local GUI1 = v:WaitForChild("PlayerGui"):FindFirstChild("BottomBox")
local GUI2 = v:WaitForChild("PlayerGui"):FindFirstChild("Leaderboard")
if GUI1 then
GUI1:Destroy()
end
if GUI2 then
GUI2:Destroy()
end
Give(v)
end
MN:Destroy()
MN = nil
end
Well after the Prepare() is called, more functions are called from said function, but there is a return in Prepare(), but that’s only if there’s less than 2 players, which this loop has so far only stopped when I have done a 2 player test myself, so that return shouldn’t be called.
function Prepare()
local Players = PlayerService:GetPlayers()
if #Players < 2 then
NotReady()
return
end
Ready(Players)
end
There’s video evidence in my 2nd reply that even though there are 2 players in the server, this loop that connects to all players only affects the one on the right side. Additionally, the “print (v)” line that starts the loop only prints 1 player, telling me that the function just stops the loop. What should happen is what happens to player on the right.
The framework goes like this
When a player first joins a server, there’s a playeradded event connected to Give() to give a GUI
Then Prepare() is called from Give() to check playercount, and if theres not enough then NotReady()
When another player joins, this player goes through those same functions, and if there is enough (which there should be,) it runs through Ready()
When the minigame is over, respawn() is called to bring all playing players back to spawn, and Give() is called to give the GUI back as I removed it when the minigame began. I thought this would create a good gameplay loop to keep checking for players and keep running the minigames, but I guess it might not.
I decided to make a different function that would due to same thing as Give() except for calling Prepare(). This worked fine. So, I guess I just have to somehow call Prepare() a different way?
I ended up making a new function that could be called from both first joining players and restarting the minigame cycle, and it works perfectly! Thanks for your time everyone.
(Also found out that LoadCharcter erases the PlayerGUI anyway so there was no need for those final lines)