I have a script working for a rounds based game. It starts with a lobby and an intermission timer of 30 seconds. Then teleports players into a chosen map within a region I defined. During the round it counts down and either ends the round after 180 seconds or if 1 player is left. Players who are killed (or remain at the end of the 180 seconds) are teleported back to the lobby and the cycle continues. I used the script below and it works well. I would like to leverage the table / array from this script to identify players who are in the region and turn off / make invisible a Spectate GUI that I would like to make visible only to players in the lobby (ie. NOT in the region I defined that encompasses the various round maps). But I'm having trouble figuring out how to amend this script. Any help would be greatly appreciated! thanks. CODE below:
'''
while true do -- repeats forever and calls the functions
wait(2)
intermissionTimer()
chooseMap()
loadMap()
wait(2)
teleportPlayers()
wait(2)
local time = roundLength
while wait(1) do
partsInRegion = workspace:FindPartsInRegion3(region, game.ServerStorage.Maps,3000) -- this returns a table
playersFound = {} -- table players found
for i, part in pairs (partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
playersFound[part.Parent.Name] = part.Parent -- add players character to table
winner = playersFound[part.Parent.Name].Name
print (winner)
print (i, part) -- 0
end
end
function Length(playersFound)
local counter = 0
for _, v in pairs(playersFound) do
counter =counter + 1
end
return counter
end
if time == 0 then
Status.Value = "Round over!"
workspace.SoundLibrary.Nowinner:Play()
break
elseif Length(playersFound)== 1 then
workspace.SoundLibrary.Winner:Play()
Status.Value = winner.. " wins!"
wait(5)
break
else
Status.Value = time .." seconds left"
time = time - 1
end
end
wait (2)
teleportBack()
deleteMap()
end
'''