So, I have a gladiators 1v1 script that works fine except for a few things:

  1. When 1 player kills the other, it does not add 1 to the plrs number value kill value
  2. it only works once right now, I want it to keep going until a button is clicked
  3. if you decide to fix this, a few things: 1. don't change the script to much, 2: don't add in the end when a button is clicked part, I can add that in myself
local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("tga1v1leaderboard","local")
local Model = script.Parent

local UpdateList
local function IncrementScore(plr,val) pcall(function() DataStore:IncrementAsync(plr.userId..".score",val) UpdateList() end) end

do -- gladiator fighting system
local MatchScreen = Model:WaitForChild("MatchScreen"):WaitForChild("SurfaceGui")
local CreateSignal = LoadLibrary("RbxUtility").CreateSignal
local Announcer = MatchScreen:FindFirstChild("Announcer",true)
local Player1Img,Player2Img = MatchScreen:FindFirstChild("Player1",true),MatchScreen:FindFirstChild("Player2",true)
local Plr1kills = Player1Img.PlayerKills.kills.Value
local Plr2kills = Player2Img.PlayerKills.kills.Value
local Pad1,Pad2 = Model:WaitForChild("Pad1"),Model:WaitForChild("Pad2")
local Spawn1,Spawn2 = Model:WaitForChild("Spawn1"),Model:WaitForChild("Spawn2")
local Return = Model:WaitForChild("Return")
local Tools = game:GetService("ReplicatedStorage"):WaitForChild("MatchTools"):GetChildren()
local GladiatorDied = CreateSignal()
local CurrentGladiators = {}
local PendingPlayers = setmetatable({},{__index = function(self,index) if index == "len" then local i = 0 for _,_ in next,self do i = i+1 end return i else return rawget(self,index) end end})
local WeaponCache = {}
local GameInProgress,GameEnding = false,false
local plr1 = ""
local plr2 = ""
local Timer do
Timer = {Time = 0,OnCompleted = CreateSignal(),Running = false,Obj = Announcer,Prop = "Text"}
	function Timer:Start(setrunning)
		if setrunning == true then
			self.Running = true
		end
		if self.Running == true then self.OnCompleted:fire() self.Running = false end
	end
	end

local function SetAnnouncer(str) Announcer.Text = str end

local function SetPadEnabled(pad,val)
	pcall(function()
		if val == true then
		pad:FindFirstChild("Mesh").Offset = Vector3.new(0,-.2,0)
		pad:FindFirstChild("PointLight").Enabled = val
		pad.BrickColor = BrickColor.new("Cyan")
		elseif val == false then
		pad:FindFirstChild("Mesh").Offset = Vector3.new(0,0,0)
		pad:FindFirstChild("PointLight").Enabled = val
		pad.BrickColor = BrickColor.new("Electric blue")
		end
	end)
end

local function SetPlayerImages(plr1,plr2)
	if plr1 ~= nil then
	Player1Img.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&userid="..plr1.userId
	else
	Player1Img.Image = ""
	end
	if plr2 ~= nil then
	Player2Img.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&userid="..plr2.userId
	else
	Player2Img.Image = ""
	end
end

local function RemoveTools(plr)
	if plr and plr:FindFirstChild("Backpack") and plr.Character then
		for i,v in next,plr.Backpack:GetChildren()do
			if v:IsA("Tool") then
				v:Destroy()
			end
		end
		for i,v in next,plr.Character:GetChildren()do
			if v:IsA("Tool") then
				v:Destroy()
			end
		end
	end
end

local function Teleport(plr,part)
local torso = part and plr.Character and plr.Character:FindFirstChild("Torso")
	if torso then
	torso.CFrame = CFrame.new(0,3+part.Size.Y/2,0)*part.CFrame
	end
end

local function playSound(plr, sound)
	if plr and plr:FindFirstChild("PlayerGui") and plr.PlayerGui:FindFirstChild(sound) then
		plr.PlayerGui:FindFirstChild(sound):Play()
	end	
end

local function stopSound(plr, sound)
	if plr and plr:FindFirstChild("PlayerGui") and plr.PlayerGui:FindFirstChild(sound) then
		plr.PlayerGui:FindFirstChild(sound):Stop()
	end	
end

local function GameEnd(plrWon,plrLost,tied,forceStopped)
stopSound(plrWon, "Music")
stopSound(plrLost, "Music")
Timer:Start(true)
for i,v in next,CurrentGladiators do CurrentGladiators[i] = nil end
	if forceStopped then
	SetAnnouncer(tostring(plrWon).." has left the game")
	wait(6)
	SetPlayerImages()
	SetAnnouncer("No match")
	elseif plrWon and tied == false then
	SetAnnouncer(plrWon.Name.." has won over "..plrLost.Name)
	playSound(plrWon, "Victory")
	IncrementScore(plrWon,1)
	wait(6)
	SetPlayerImages()
	SetAnnouncer("No match")
	elseif tied == true then
	SetAnnouncer(plrWon.Name.." was tied with "..plrLost.Name)
	wait(6)
	SetPlayerImages()
	SetAnnouncer("No match")
	else
	SetAnnouncer("Time ran out")
		if plrWon and plrWon.Character then
		Teleport(plrWon,Return)
		end
		if plrLost and plrLost.Character then
		Teleport(plrLost,Return)
		end
	wait(6)
	SetPlayerImages()
	SetAnnouncer("No match")
	end
end

local function DeclareVictor(plrWon,plrLost)
--print(plrWon.Name.." won")
if plrWon == plr1 then
Plr1kills = Plr1kills + 1
wait(4)
Teleport(plrWon,Spawn1)
Teleport(plrLost,Spawn2)
else if plrWon == plr2 then
	Plr2kills = Plr2kills + 1
	wait(4)
	Teleport(plrWon,Spawn2)
	Teleport(plrLost,Spawn1)
plrWon.Character:FindFirstChild("Humanoid"):UnequipTools()
RemoveTools(plrWon)
game.ReplicatedStorage.MatchTools.TKsword:Clone().Parent = game.Players:FindFirstChild(plr1.Name).Backpack
game.ReplicatedStorage.MatchTools.TKsword:Clone().Parent = game.Players:FindFirstChild(plr2.Name).Backpack
GameInProgress,GameEnding = false,false
end
end
end
local function DeclareTie(plr1,plr2)
wait(4)
Teleport(plr1,Spawn1)
Teleport(plr2,Spawn2)
plr1.Character:FindFirstChild("Humanoid"):UnequipTools()
plr2.Character:FindFirstChild("Humanoid"):UnequipTools()
RemoveTools(plr1)
RemoveTools(plr2)
game.ReplicatedStorage.MatchTools.TKsword:Clone().Parent = game.Players:FindFirstChild(plr1.Name).Backpack
game.ReplicatedStorage.MatchTools.TKsword:Clone().Parent = game.Players:FindFirstChild(plr2.Name).Backpack
GameInProgress,GameEnding = false,false
end

local function GetOpposingGlad(glad)
for i,v in next,CurrentGladiators do if v ~= glad then return v end end
end

local function OnGladiatorDied(plr)
--print(plr.Name.." died")
	if not GameEnding then
	GameEnding = false
	
	local victor,tied = GetOpposingGlad(plr),false
	wait(3)
	local victorHum = victor.Character:WaitForChild("Humanoid")
	if victorHum.Health <= 0 then tied = true end
		if tied == false then
		DeclareVictor(victor,plr)
		if victor == plr1 then
			Plr1kills = Plr1kills + 1
		end
        if victor == plr2 then
			Plr2kills = Plr2kills + 1
end
		else
		DeclareTie(plr,victor)
		end
	end
end

local function SpawnPlayer(plr,part)
local hum = plr.Character and plr.Character:WaitForChild("Humanoid")
local weaponCache = {}
WeaponCache[plr] = weaponCache
for i,v in next,plr:WaitForChild("Backpack"):GetChildren() do v.Parent = nil weaponCache[#weaponCache+1] = v end
for i,v in next,Tools do v:Clone().Parent = plr:FindFirstChild("Backpack") end
Teleport(plr,part)
	coroutine.wrap(function()
	hum.Died:wait()
		if (function() for i,v in next,CurrentGladiators do if v == plr then return true end end return false end)() then
		OnGladiatorDied(plr)
		end
	end)()
end

local function StartGame(plr1,plr2)
SetPlayerImages(plr1,plr2)
SetAnnouncer (plr1.Name.." vs "..plr2.Name)
	coroutine.wrap(function()
		local e = Timer.OnCompleted:connect(function()
		GameEnding = true
		GameEnd(plr1,plr2,0)
		GameInProgress,GameEnding = false,false
		end)
	repeat wait() until GameEnding == true
	e:disconnect()
	end)()
	coroutine.wrap(function()
	repeat wait() until plr1.Parent ~= Players or plr2.Parent ~= Players or GameInProgress == false
		if GameInProgress == true then
		GameEnding = true
		
		local leftPlr = plr1.Parent ~= Players and plr1 or plr2
		local remainingPlr = plr1 == leftPlr and plr2 or plr1
		Teleport(remainingPlr,Return)
		if remainingPlr.Character:FindFirstChild("Humanoid") then 
			remainingPlr.Character.Humanoid:UnequipTools() 
			remainingPlr.Character.Humanoid.Health=100 
		end
		RemoveTools(remainingPlr)
		GameEnd(leftPlr,nil,false,true)
		GameInProgress,GameEnding = false,false
		end
	end)()
	if math.random(0,1) == 1 then
	SpawnPlayer(plr1,Spawn1)
	SpawnPlayer(plr2,Spawn2)
	else
	SpawnPlayer(plr2,Spawn1)
	SpawnPlayer(plr1,Spawn2)
	end
	playSound(plr1, "Music")
	playSound(plr2, "Music")
end

local function Check()
	--print("Checking")
	print(PendingPlayers.len)
	print(#CurrentGladiators)
	print(GameInProgress)
	if PendingPlayers.len == 2 and #CurrentGladiators < 2 and GameInProgress == false then
	GameInProgress = true
	for i,v in next,PendingPlayers do CurrentGladiators[#CurrentGladiators+1] = v end
	plr1,plr2 = unpack(CurrentGladiators)
		if plr1 ~= plr2 then
		StartGame(plr1,plr2)
		end
	end
end


local function PlayerTouched(pad,plr)
	if (function() for i,v in next,PendingPlayers do if i == pad then return false end end return true end)() then
	local isOnPad,torso,hum = true,plr.Character and plr.Character:WaitForChild("Torso"),plr.Character and plr.Character:WaitForChild("Humanoid")
		if hum.Health > 0 then
		PendingPlayers[pad] = plr
		SetPadEnabled(pad,true)
		coroutine.wrap(function()
		repeat wait() until #CurrentGladiators < 2 or isOnPad == false
			if isOnPad == true then
			wait(1)
			Check()
			end
		end)()
		repeat wait() until torso.Position.X>pad.Position.X+pad.Size.X/2+1 or
			torso.Position.X<pad.Position.X-pad.Size.X/2-1 or
			torso.Position.Z>pad.Position.Z+pad.Size.Z/2+1 or
			torso.Position.Z<pad.Position.Z-pad.Size.Z/2-1 or
			hum.Health <= 0 or plr.Parent ~= Players
		isOnPad = false
		SetPadEnabled(pad,false)
		PendingPlayers[pad] = nil
		end
	end
end

Pad1.Touched:connect(function(hit) local plr = Players:GetPlayerFromCharacter(hit.Parent) if plr then PlayerTouched(Pad1,plr) end end)
Pad2.Touched:connect(function(hit) local plr = Players:GetPlayerFromCharacter(hit.Parent) if plr then PlayerTouched(Pad2,plr) end end)
end

2 comments

0

Jesus man. Do you think you could show the part of the script that isnt working.

0

It works except for what is listed.