Hi, I’m currently trying to create a script that makes a round system that teleports players to the map after intermission is over and teleports them back once the round itself is over, my current issue is that the script only teleports one player to and from the map, there are no errors during testing nor playing the game itself.
Suggestions regarding other issues are appreciated!
--Variables
local lobbyPart = game.Workspace.SpawnLocation
local maps = game.ReplicatedStorage.Folder:GetChildren()
local status = game.ReplicatedStorage.Status
local inRound = game.ReplicatedStorage:WaitForChild("InRound")
local playersAlive = {}
local function choseMap(char, internval) -- chose map
local mapsNo = math.random(1, #maps)
local chosenMap = maps[mapsNo]:Clone()
chosenMap.Parent = workspace
print(chosenMap.Name)
char.HumanoidRootPart.Position = chosenMap.TeleportPoint.Position
if internval == 0 then
task.wait(4)
chosenMap:Destroy()
end
end
local function round() -- start intermission and round
local sword = game.ReplicatedStorage.ClassicSword:Clone()
for i, v in pairs(game.Players:GetPlayers()) do
table.insert(playersAlive, i, v)
if inRound == true then
inRound = false
break
end
local char = v.Character or v.CharacterAdded:Wait()
if char.Humanoid then
local hum = char.Humanoid
for i = 30, 0, -1 do
status.Value = "Intermission: "..i
task.wait(1)
end
choseMap(char,i)
status.Value = "Map Chosen!"
task.wait(5)
sword.Parent = v.Backpack
for i = 120, 0, -1 do -- change i to 120 when done testing, 10 during testing
hum.Died:Connect(function()
table.remove(playersAlive, i)
print(playersAlive)
if #playersAlive == 1 then
local winner = playersAlive[i]
status.Value = "Round Ended"
wait(5)
inRound = true
if v.Name == winner.Name then
local leaderstats = playersAlive[i].leaderstats
local coins = leaderstats.Coins
local wins = leaderstats.Wins
wins.Value = wins.Value + 1
coins.Value = coins.Value + 200
coins.Value = coins.Value
else
local leaderstats = v.leaderstats
local coins = leaderstats.Coins
coins.Value = coins.Value + 50
end
end
end)
status.Value = "Time Left: "..i
if i == 0 then
sword:Destroy()
v.Character.HumanoidRootPart.Position = lobbyPart.Position
end
task.wait(1)
end
end
end
end
while true do
round()
task.wait(1)
end