Error from player:LoadCharacter() stopping script

I want to have a function respawn 2 players at the first spawnlocation in the game. If a player leaves they lose the match, but the problem is that LoadCharacter also stops the script because they aren’t in the world.

I’ve tried checking with if statements so the script won’t try to load their character, but it never worked.
Here is the function I am using.

local function matchOver(player, w, l)
	do
		Match = false
		Winner.Value = w.Name
		Loser.Value = l.Name
		ShowWinner:FireAllClients(player,Winner,Loser)
		wait(5)
		
		w.RespawnLocation = spawnloc l.RespawnLocation = spawnloc
		w:LoadCharacter() l:LoadCharacter()
		
		List[1] = nil
		List[2] = nil
		Winner.Value = ""
		Loser.Value = ""
		Round.Value = 0
		Countdown = 3
		Return:FireAllClients()
	end
end

maybe this? I can think of OPP stuffs so:

local function Round:Start()
    if not self.InProgress then
        self.InProgress = true
        local playerInTable = {}
        — apply your logic here to insert 2 players in the table, then loop through the table to connect the players to an event, then make the event to end the round
    end
end)

Sorry if this is confusing.

Not really confusing to me so I might try it, I just thought of something though so I’ll update you.

OOP could help, so keep in mind.

I got it to work I just had to change the w and l variables. I’ll remember to use OOP to script these kinds of things next time though, thanks.

1 Like