Okay, so me and my bro are developing a round-based obby game, and I am having a little trouble with the lobby script. I can now teleport players around the place, but I haven’t quite figured out how to detect how many players are still in a round. My script below (placed in ServerScriptService) has a variable that will reset, then increase in value according to the ipairs function. I have this outputting to a Value placed in StarterGui, then a GUI that is synced to that Value, so I can effectively debug the system. Now the problem. I have a Part placed in one of the maps with a script that will decrease the Value by 1. This much does not work. I have included the script that is placed in ServerScriptService below:
PlayersAlive = 0
--FUNCTION DEFINING
function teleportTo(x,y,z)
target = CFrame.new(x,y,z) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
--Make sure the character exists and its HumanoidRootPart exists
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
--add an offset of 5 for each character
player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
end
PlayersAlive = PlayersAlive + 1
game.StarterGui.PlayersAlive.Value = PlayersAlive
end
end
function postToGui(text)
game.StarterGui.String1.Value = text
end
---------------------------------------------------------------------------------
----------------------------ON TO THE MAIN SCRIPT :D-----------------------------
while true do
PlayersAlive = 0
workspace.one:Play()
workspace.SoundO:Play()
for x = 45, 0, -1 do
postToGui("INTERMISSION: " .. x)
wait(1)
end
workspace.one:Stop()
selection = 1 --math.random(1,4)
if selection == 1 then
teleportTo(1000, 1.5, 669)
print("Lava Obby selected!")
postToGui("Lava Obby by Destruct_ed selected!")
workspace.LavOb:Play()
elseif selection == 2 then
teleportTo(47.08, 7.5, -566.94)
print("Facility Breakdown selected!")
postToGui("Facility Breakdown by Destruct_ed selected!")
workspace.FacBdown:Play()
elseif selection == 3 then
teleportTo(104.71, 17.5, -141.22)
print("Generic Cat Food by Destruct_ed selected!")
postToGui("Generic Cat Food by Destruct_ed selected!")
workspace.GenC:Play()
elseif selection == 4 then
teleportTo(256, 13.51, 423)
print("Broken Savanna by Regen_erate selected!")
postToGui("Broken Savanna by Regen_erate selected!")
workspace.BrokSav:Play()
end
workspace.SoundI:Play()
i = 60
for i = 120, 0, -1 do
wait(1)
game.StarterGui.String1.Value = "IN ROUND: " .. i
if game.StarterGui.PlayersAlive.Value == 0 then break end
end
teleportTo(0,0,0)
workspace.FacBdown:Stop()
workspace.LavOb:Stop()
workspace.GenC:Stop()
workspace.BrokSav:Stop()
end
Suggestions?