Is there any way to get a script to return to a certain line of code? (SOLVED)
Asked by
5 years ago Edited 5 years ago
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:
1 | function IfLeftGerman(User) |
2 | if User.Name = = GermanLeader.Name then |
6 | game.Players.PlayerRemoving:Connect(IfLeftGerman) |
This is my code right now:
01 | local Players = game:GetService( 'Players' ) |
02 | local pCount = Players:GetPlayers() |
10 | print ( "Not Enough Players To Make Leader!" ) |
13 | French = game.Teams.French:GetPlayers() |
14 | Germans = game.Teams.Prussians:GetPlayers() |
16 | GermanLeader = (Germans [ math.random(#Germans) ] ) |
17 | FrenchLeader = (French [ math.random(#French) ] ) |
19 | Tag = Instance.new( "NumberValue" , GermanLeader.Character) |
20 | Tag.Name = "LeaderTag" |
21 | TagScript = game.ServerScriptService.Holder.TagScript:Clone() |
22 | TagScript.Parent = Tag |
23 | TagScript.Disabled = false |
25 | Tag 1 = Instance.new( "NumberValue" , FrenchLeader.Character) |
26 | Tag 1. Name = "LeaderTag" |
27 | TagScript 1 = game.ServerScriptService.Holder.TagScript:Clone() |
28 | TagScript 1. Parent = Tag |
29 | TagScript 1. Disabled = false |
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.