So, I’m making a 1v1 system. Pretty much, it selects 2 users randomly and after they complete their entrances (not done but the function is included), they’re in a match against eachother.
The script is functional, but I totally forgot to add a detector incase a player leaves before (if selected) or during the match.
I’ve tried using a separate function, but then I’d have to add even more while statement do’s.
Could anyone help me sort this out? I’m really inexperienced when it comes to ending functions all of the sudden.
Code:
local selected1
local selected2
falls = game.Workspace.System.Falls
ongoing = false
local wrestler1position = game.Workspace.Teleporting.W1
local wrestler2position = game.Workspace.Teleporting.W2
function ForceEndMatch()
if game.Players:GetPlayers()[selected1] == nil then
print("Winner is "..game.Players:GetPlayers()[selected2].Name)
end
if game.Players:GetPlayers()[selected2] == nil then
print("Winner is "..game.Players:GetPlayers()[selected1].Name)
end
end
function EndMatch(winner)
print(game.Players:GetPlayers()[winner].Name.." has won the match")
end
function StartMatch()
--turns the match on
ongoing = true
spawn(function()
while ongoing == true do
wait()
if falls.Wrestler1.Value == 3 and falls.Wrestler2.Value < 3 then
EndMatch(selected1)
ongoing = false
elseif falls.Wrestler2.Value == 3 and falls.Wrestler1.Value < 3 then
EndMatch(selected2)
ongoing = false
end
end
end)
print("recognized")
--first fall adjustments
game.Workspace:WaitForChild(game.Players:GetPlayers()[selected1].Name)
game.Workspace:WaitForChild(game.Players:GetPlayers()[selected2].Name)
game.Players:GetPlayers()[selected1].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler1position.Position)
game.Players:GetPlayers()[selected2].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler2position.Position)
local clean = game.ServerStorage.Clean:Clone()
clean.Parent = game.Players:GetPlayers()[selected1].Backpack
clean.Parent = game.Players:GetPlayers()[selected2].Backpack
wait(1)
while ongoing == true do
wait(1)
--wrestler1 dies
if game.Players:GetPlayers()[selected1].Character.Humanoid.Health == 0 and game.Players:GetPlayers()[selected1] ~= nil then --player died, waiting if another person dies
print(game.Players:GetPlayers()[selected1].Name.." has died, waiting on toolstep")
wait(2)
if game.Players:GetPlayers()[selected2].Character.Humanoid.Health == 0 and game.Players:GetPlayers()[selected2] ~= nil then --another player also died, toolstep
print("Both players down")
wait(5)
game.Players:GetPlayers()[selected1].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler1position.Position)
game.Players:GetPlayers()[selected2].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler2position.Position)
local clean = game.ServerStorage.Clean:Clone()
clean.Parent = game.Players:GetPlayers()[selected1].Backpack
clean.Parent = game.Players:GetPlayers()[selected2].Backpack
else
falls.Wrestler2.Value = falls.Wrestler2.Value + 1
print(game.Players:GetPlayers()[selected2].Name.." has gained a fall")
wait(5)
if ongoing == true then
game.Players:GetPlayers()[selected1].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler1position.Position)
game.Players:GetPlayers()[selected2].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler2position.Position)
local clean = game.ServerStorage.Clean:Clone()
clean.Parent = game.Players:GetPlayers()[selected1].Backpack
end
end
end
--wrestler2 dies
if game.Players:GetPlayers()[selected2].Character.Humanoid.Health == 0 and game.Players:GetPlayers()[selected2] ~= nil then --player died, waiting if another person dies
print(game.Players:GetPlayers()[selected2].Name.." has died, waiting on toolstep")
wait(2)
if game.Players:GetPlayers()[selected1].Character.Humanoid.Health == 0 and game.Players:GetPlayers()[selected1] ~= nil then --another player also died, toolstep
print("Both players down")
wait(5)
game.Players:GetPlayers()[selected1].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler1position.Position)
game.Players:GetPlayers()[selected2].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler2position.Position)
local clean = game.ServerStorage.Clean:Clone()
clean.Parent = game.Players:GetPlayers()[selected1].Backpack
clean.Parent = game.Players:GetPlayers()[selected2].Backpack
else
falls.Wrestler1.Value = falls.Wrestler1.Value + 1
print(game.Players:GetPlayers()[selected1].Name.." has gained a fall")
wait(5)
if ongoing == true then
game.Players:GetPlayers()[selected1].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler1position.Position)
game.Players:GetPlayers()[selected2].Character.HumanoidRootPart.CFrame = CFrame.new(wrestler2position.Position)
local clean = game.ServerStorage.Clean:Clone()
clean.Parent = game.Players:GetPlayers()[selected2].Backpack
end
end
end
end
end
function Entrances()
--entrance1
print("Entrance 1")
wait(20)
--end if a brick is touched
--entrance2
print("Entrance 2")
wait(5)
--end if a brick is touched
StartMatch()
end
function GetWrestlers()
repeat
--get all players in the server
local players = game:GetService("Players")
local playerlist = players:GetPlayers()
wait(.2)
selected1 = math.random(1,#playerlist)
print (playerlist[selected1].Name.." picked, checking if they've been picked")
--check
if playerlist[selected1] ~= playerlist[selected2] and playerlist[selected1] ~= nil then
print("valid for choice")
else
print (playerlist[selected1].Name.." already in the match, restarting the randomizer")
end
until playerlist[selected1] ~= playerlist[selected2] and playerlist[selected1] ~= nil
print(game.Players:GetPlayers()[selected1].Name.." is valid, inserted")
--wrestler 2
repeat
--get all players in the server
local players = game:GetService("Players")
local playerlist = players:GetPlayers()
wait(.2)
selected2 = math.random(1,#playerlist)
print (playerlist[selected2].Name.." picked, checking if they've been picked")
--check
if playerlist[selected2] ~= playerlist[selected1] and playerlist[selected2] ~= nil then
print("valid for choice")
else
print (playerlist[selected2].Name.." already in the match, restarting the randomizer")
end
until playerlist[selected2] ~= playerlist[selected1] and playerlist[selected2] ~= nil
print(game.Players:GetPlayers()[selected2].Name.." is valid, inserted")
print("Starting entrances")
Entrances()
end
repeat wait(1) until game.Players.NumPlayers >= 2
GetWrestlers()
The script itself is unfinished, but this is a core-based prototype which is needed for it to function.
Any help is appreciated!