Player leaves and script breakes

I have a round script and in it theres a part that randomly chooses 2 players.

After a player leaves during it, I get an error on these lines:

status.Value = "Teleporting ..."
wait(1.5)

status.Value = "Teleporting ".. duelist1 .." .."
wait(1)

status.Value = "Teleporting ".. duelist1 .." and " .." ."
wait(1.5)

status.Value = "Teleporting ".. duelist1 .." and ".. duelist2 .."!"
wait(1.5)

Theres also a long code above this one that randomly chooses 2 players that I won’t paste into here because you probably get the gist of it.

Is there any way that I could loop the code that randomly chooses 2 players and this one until its successful?

I was making coroutines and a lot of unnecessary stuff that didn’t work and gave up. The logic I used was to check if a player left and to check if leavingplayer.Name == duelist1 (duelist1 and duelist2 are player names, player instances are duel1 and duel2) then do something but I couldn’t get any further

I would love to see some of your solutions as mine haven’t worked at all

1 Like

Chances are since one of the players left, their name would be invalidated. I’m assuming along with these lines you teleport them both. Check for each player as you teleport them, and end the duel if either of them leave.

And how would I go about checking for them? Do I use the PlayerRemoving event and compare UserId between every wait()?

I would recommend just checking in Players if the username is still there.

if not players:FindFirstChild(duelist1) then
	print("Player left!")
end
1 Like

Thank you, I will try your suggestion and come back to reply

Ok so this works only sometimes? I guess it’s an error on my side but I should be able to fix this. Thanks for the help man

1 Like

No problem! Glad I helped. Make sure you’re checking for both duelist1 and duelist2 every check:

if not players:FindFirstChild(duelist1) or not players:FindFirstChild(duelist2) then
	print("Player left!")
end

Yes, I’m checking for duelist1 during the

and checking for duelist 2 during

Also, I made a local function for the players that get randomly chosen but I need to return multiple values like the player, his name, and the seat he was sitting on. Do you maybe know how I could get those values?

My current return looks like this, but I’m not sure how to assign these values

return duel1,duelist1,duelseat1,duel2,duelist2,duelseat2

If you want to, we can take this to private DMs for more easy talking.

If it’s fine with you then sure

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.