My Roblox Game Breaks After A Player Leaves

  1. What do you want to achieve? Keep it simple and clear!
    I want the game to not break after a player leaves.

  2. What is the issue? Include screenshots / videos if possible!
    The game breaks, immediately after a player leaves when the game starts and/or the game has started. The only thing you can do is move your Roblox character.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t found any solutions yet. ‘ResetOnSpawn’ property has already been turned off for all Screen GUIs, and player:LoadCharacter() was removed.

What should I do? :frowning_face:

Edit: Fixed the game breaking during intermission

1 Like

Are you testing this with multiple simulated clients in roblox studio or in a live experience? Either way, you should check for any errors in the output that might point you towards an issue. If you’re in studio you can view this from the window labeled “Server”. If you’re in a live experience, you can press F9 to view the Developer Console, then check the “Server” logs.

2 Likes

I’m doing a local test with 2 players and a local server

Most likely the issue is improper handling of a server script, where you didn’t take into account that people might leave during your game.

2 Likes

Here’s my player removing function:

-- Fires when a player is about to leave the game
local function player_removing(player: Player)
	update_status("A player left the game! Restarting..")
	
	-- cleanup for the seeker
	if player and player == nils.current_seeker then
		nils.current_seeker = nil
		
		if nils.seeker_touched_connection then
			nils.seeker_touched_connection:Disconnect()
			nils.seeker_touched_connection = nil
		end
	end
	
	-- cleanup for hiders
	for i, v in ipairs(hiders) do
		if v == player then
			table.remove(hiders, i)
			break
		end
	end
	
	modules.debounce_helper_SERVER.cancel_task()
	
	modules.cleanup_loops_SERVER.call(player, true, debounces)
	modules.cleanup_loops_SERVER.call(player, true, player_flags)
	modules.cleanup_loops_SERVER.call(player, true, nils)
	
	check_plr_count()
end

game.Players.PlayerRemoving:Connect(player_removing)
modules.server_shutdown_handler.doing_my_job(player_removing)

check_plr_count:

local function check_plr_count()
	local ColorCorrection = game.Lighting:WaitForChild("ColorCorrection")
	local plr_check_msg = "Not Enough Players! " .. players_needed_to_start .. " Players Needed!"
	
	if #game.Players:GetPlayers() < players_needed_to_start then
		print("Player count:", #game.Players:GetPlayers())
		
		update_status(plr_check_msg)
		TextLabel_text_part.Text = plr_check_msg
		
		for _, plr in ipairs(game.Players:GetPlayers()) do
			player_flags.game_in_progress[plr.UserId] = false
			remotes.reward_info_event:FireClient(plr, points_to_give_hiders, points_to_give_seekers)
			
			ColorCorrection.Brightness = 0
			game.Lighting.ClockTime = 9
		end
	else
		print("added or removing triggered")
		TextLabel_text_part.Text = "Vote for the Next Map!"
		game_loop()
	end
	
	game_active = false
end

‘spawning coins’ duplicates were removed:

 22:39:49.889  Test mode is OFF  -  Server - test_mode:16
  22:39:49.890  Spawning coins  -  Server - main:446
  22:39:49.890   ▶ Coin instance was created (x2)  -  Server - main:438
  22:39:49.890  Spawning more coins  -  Server - main:452
  22:39:49.890  Coin instance was created  -  Server - main:438
  22:39:49.894   ▶ Network owner secured! (x13)  -  Server - secure_network:8
  22:39:49.905   ▶ Shadows off! (x13)  -  Server - shadows_off:9
  22:39:49.916  Today is not the weekend. No notifications will be sent.  -  Server - send_notifications:42
  22:40:00.021  Not the weekend! date_checker  -  Server - event_messages:28
  22:40:00.022  Lock  -  Server - main:323
  22:40:00.022  Applying seeker chances  -  Server - main:274
  22:40:00.022  Player count: 1  -  Server - main:299
  22:40:00.022  Status updated  -  Server - main:288
  22:40:00.098  Not the weekend! date_checker  -  Server - event_messages:28
  22:40:00.098  Lock  -  Server - main:323
  22:40:00.098  Applying seeker chances  -  Server - main:274
  22:40:00.098  added or removing triggered  -  Server - main:312
  22:40:00.278   ▶ Data saved! (x2)  -  Server - handle_player_data:49
  22:40:01.028  custom badges called  -  Server - custom_badges:26
  22:40:01.028  Player1 got welcome badge!  -  Server - welcome_badge:44
  22:40:01.028  Player2 got welcome badge!  -  Server - welcome_badge:44

I fixed intermission, and I am left with: when the game starts and/or the game has started

Fixed the bug after checking for player existence under the for loops and after more debugging