Whys this broken?

> local PlayersService = game:GetService("Players")
> 
> local intermissionMusic = workspace.Music.IntermissionMusic
> local fightMusic = workspace.Music.FightMusic
> 
> local lobby = workspace.Lobby
> local maps = game.ReplicatedStorage.maps:GetChildren()
> local status = game.ReplicatedStorage.Status
> 
> local gameTime = 60
> local intermissionTime = 5
> 
> while true do
> 	for i = intermissionTime, 0, -1 do
> 		status.Value = "intermission :D : " .. i
> 		task.wait(1)
> 	end
> 
> 	local numPlayers = #PlayersService:GetPlayers()
> 	
> 	if numPlayers < 2 then
> 		status.Value = "need more players :("
> 		wait(3)
> 
> 		for i = 10, 1, -1 do
> 			status.Value = "waiting for more players: " .. i
> 			task.wait(1)
> 		end
> 
> 		continue
> 	end
> 
> 	local pickedMap = maps[math.random(1, #maps)]
> 	local clonedMap = pickedMap:Clone()
> 
> 	for i = 5, 0, -1 do
> 		status.Value = "generating map :) : " .. i
> 		task.wait(1)
> 	end
> 
> 	status.Value = "map generated: " .. clonedMap.Name
> 	clonedMap.Parent = game.Workspace
> 
> 	task.wait(8)
> 
> 	local tps = pickedMap.Spawns:GetChildren()
> 	local spawnedPlayers = {} 
> 
> 	for _, player in pairs(PlayersService:GetPlayers()) do
> 		local character = player.Character
> 
> 		if character and #spawnedPlayers < 2 then
> 			local hrp = character.HumanoidRootPart
> 			local randomSpawn
> 
> 			repeat
> 				randomSpawn = tps[math.random(1, #tps)]
> 			until not spawnedPlayers[randomSpawn]
> 
> 			spawnedPlayers[randomSpawn] = true
> 			hrp.CFrame = randomSpawn.CFrame
> 		end
> 	end
> 
> 	for i = 1, 10 do
> 		intermissionMusic.Volume -= 0.05
> 		wait(0.1)
> 	end
> 
> 	fightMusic.Playing = true
> 	intermissionMusic.Playing = false
> 
> 	for i = 1, 10 do
> 		fightMusic.Volume += 0.05
> 		wait(0.1)
> 	end
> 
> 	for i = gameTime, 0, -1 do
> 		status.Value = "Fight >:D : " .. i
> 		task.wait(1)
> 	end
> 
> 	for i, player in pairs(PlayersService:GetPlayers()) do
> 		local character = player.Character
> 
> 		if character then
> 			local hrp = character.HumanoidRootPart
> 			hrp.CFrame = lobby.Spawn.CFrame
> 		end
> 	end
> 
> 	for i = 1, 10 do
> 		fightMusic.Volume -= 0.05
> 		wait(0.1)
> 	end
> 
> 	fightMusic.Playing = false
> 	intermissionMusic.Playing = true
> 
> 	for i = 1, 10 do
> 		intermissionMusic.Volume += 0.05
> 		wait(0.1)
> 	end
> 	
> 	spawnedPlayers = {}
> 	clonedMap:Destroy()
> end

it breaks when other people join the game while game is going on it like stops midway n stuff plz help lol

1 Like

What do you mean by “it breaks”? Can you be more detailed? Could you also format your code correctly next time?

it picks 2 players when it starts but if someone else joins anytime after it starts it breaks and next game it just stays at generating map status

Where is this script, and also where is the client script?

inside serverscript service and the only client script is inside the gui

local statusValue = game.ReplicatedStorage:WaitForChild(“Status”)
local mainText = script.Parent:WaitForChild(“text”)

statusValue:GetPropertyChangedSignal(“Value”):Connect(function()
mainText.Text = statusValue.Value
end)