Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Player leaves game ends up breaking?

I made a mini game script for two random players going against another, and I'm not going to give the whole script to bore you out, but I will give you the main section. Usually when a player dies, the other player wins. But what I realize was that when a player leaves during the round, the game ends up breaking. I do not know how to make a script line where if a player leaves the other gets victory, and help?

repeat
		wait()
		if f1.Character.Humanoid.Health <= 0 then--declare winners
			winner = f2
		elseif f2.Character.Humanoid.Health <= 0 then
			winner = f1
		end
	until winner ~= nil
	if winner:findFirstChild("leaderstats") then
		if winner.leaderstats:findFirstChild(stat) then
			winner.leaderstats[stat].Value = winner.leaderstats[stat].Value + 1
		end
	end
	m.Value = "The winner is... "..winner.Name.."!"
	wait(1)
	game.Workspace.Crowd1:Play()
	wait(10)
	game.Workspace.Crowd1:Stop()
	wait(1)
	winner.Character:BreakJoints()
	winner = nil
end

1 answer

✓ Accepted answer
local Players = game:GetService("Players")

repeat wait()
	if not Players:FindFirstChild(f1.Name) or (f1.Character.Humanoid.Health <= 0)  then 
		winner = f2
	
	elseif not Players:FindFirstChild(f2.Name) or (f2.Character.Humanoid.Health <= 0) then 
		winner = f1
	end
until winner ~= nil

This discussion is preserved as it was. New answers, comments, and votes are closed.