I've made this script that selects a random player to be a leader for each team in my game and it works fine, although I wanted to know if that upon a player leaving the game (specifically the leader) if there was a way to start the script over but avoid waiting 10 minutes again to select a new leader. I know how to use the PlayerRemoving event, but I don't know if there's a way to return to a line of code instead of starting the script over. For Example:
function IfLeftGerman(User)
if User.Name == GermanLeader.Name then
-- return to line of code
end
game.Players.PlayerRemoving:Connect(IfLeftGerman)
This is my code right now:
local Players = game:GetService('Players')
local pCount = Players:GetPlayers()
while true do
wait(600)
-- Where I want the script to restart if the leader leaves
if #pCount < 2 then
print("Not Enough Players To Make Leader!")
else
French = game.Teams.French:GetPlayers()
Germans = game.Teams.Prussians:GetPlayers()
GermanLeader = (Germans[ math.random(#Germans)])
FrenchLeader = (French[ math.random(#French)])
Tag = Instance.new("NumberValue", GermanLeader.Character)
Tag.Name = "LeaderTag"
TagScript = game.ServerScriptService.Holder.TagScript:Clone()
TagScript.Parent = Tag
TagScript.Disabled = false
Tag1 = Instance.new("NumberValue", FrenchLeader.Character)
Tag1.Name = "LeaderTag"
TagScript1 = game.ServerScriptService.Holder.TagScript:Clone()
TagScript1.Parent = Tag
TagScript1.Disabled = false
-- PlayerRemoving event would go here
end
end
I believe I could still make the script work with another method, although it'd be a lot longer and messy. I want to know if there was a simple way to return to a certain line in a script.

1 comment
It worked! Thank you so much, this cut the code down about 40 lines.