Help with FireClient Error

I forgot lua’s arrays start at 1, not 0. So it should be like this:

-- Wait until both the players input something, or one leaves the game.
repeat task.wait() until not (DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value and Corners[1].Occupant.Value and Corners[2].Occupant.Value) or ((AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= ""))

-- Checks if player leaves the ring
local hasPlayers = DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value and Corners[1].Occupant.Value and Corners[2].Occupant.Value

It is still giving me the error

Can I take a look at the whole script?

local PP = script.Parent.Proximity.ProximityPrompt
local Billboard = script.Parent.Billboard.BillboardGui

local Rep = game:GetService("ReplicatedStorage")
local Event = Rep.Client.LeaveEvent

local MPS = game:GetService("MarketplaceService")

local Attacker = script.Parent.Attacker
local Defender = script.Parent.Defender

local Corners = {script.Parent.Corner1, script.Parent.Corner2}
local Occupants = 0


local function StartFight()
	local AttackingPlayer:Player = game.Players:GetPlayerFromCharacter(Attacker.Value)
	local DefendingPlayer:Player = game.Players:GetPlayerFromCharacter(Defender.Value)

	AttackingPlayer.Backpack.Data.CurrentLives.Value = 20
	DefendingPlayer.Backpack.Data.CurrentLives.Value = 20

	game.ReplicatedStorage.Client.ChangeIcons:FireClient(AttackingPlayer, DefendingPlayer.UserId)
	game.ReplicatedStorage.Client.ChangeIcons:FireClient(DefendingPlayer, AttackingPlayer.UserId)

	local Switch = false
	local Rows = {}
	while (DefendingPlayer.Backpack.Data.CurrentLives.Value > 0) do		
		if Switch then
			local TempPlayer = AttackingPlayer
			AttackingPlayer = DefendingPlayer
			DefendingPlayer = TempPlayer
			Switch = false
		end

		AttackingPlayer.Backpack.Data.State.Value = "Attack"
		DefendingPlayer.Backpack.Data.State.Value = "Defend"

		-- Wait until both the players input something, or one leaves the game.
		repeat task.wait() until not (DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value and Corners[1].Occupant.Value and Corners[2].Occupant.Value) or ((AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= ""))

		-- Checks if player leaves the ring
		local hasPlayers = DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value and Corners[1].Occupant.Value and Corners[2].Occupant.Value

		
		print(not hasPlayers)
		
		if not hasPlayers then
			Attacker.Value = nil
			Defender.Value = nil	

			for i, v in pairs(Corners) do
				if v.Occupant.Value ~= nil then
					local player = game.Players:GetPlayerFromCharacter(v.Occupant.Value)

					v.Occupant.Value.HumanoidRootPart.Anchored = false
					player.Backpack.Data.State.Value = ""
					player.Backpack.Data.Ring.Value = nil		
				end

				v.Occupant.Value = nil
			end

			Occupants = 0
			Billboard.TextLabel.Text = "0/2"

			-- Completely stop the game
			return
		end

		local AttackerChose = AttackingPlayer.Backpack.Data.ChosenMove.Value
		local DefenderChose = DefendingPlayer.Backpack.Data.ChosenMove.Value

		print("Attacker Chose", AttackerChose)
		print("Defender Chose", DefenderChose)
		local PlayedAnimation = false
		if AttackerChose == DefenderChose then
			print("Defender Loses a life, Total:", DefendingPlayer.Backpack.Data.CurrentLives.Value)
			DefendingPlayer.Backpack.Data.CurrentLives.Value -= 1

			print(Rows)
			table.insert(Rows, DefendingPlayer.Backpack.Data.ChosenMove.Value)
			for i, v in pairs(Rows) do
				PlayedAnimation = true
				AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
				DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
				wait(0.5)
			end
			if #Rows == 3 then
				DefendingPlayer.Backpack.Data.CurrentLives.Value = 0
			end
			game.ReplicatedStorage.Client.HideButton:FireClient(AttackingPlayer, "Attack", AttackerChose)
			game.ReplicatedStorage.Client.HideButton:FireClient(DefendingPlayer, "Defend", DefenderChose)
		else
			for i, v in pairs(Rows) do
				AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
				DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
				wait(0.5)
			end

			Rows = {}
			Switch = true
		end
		if not PlayedAnimation then
			AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..AttackingPlayer.Backpack.Data.ChosenMove.Value]):Play()
			DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..DefendingPlayer.Backpack.Data.ChosenMove.Value]):Play()
		end

		wait(1)
		AttackingPlayer.Backpack.Data.ChosenMove.Value = ""
		DefendingPlayer.Backpack.Data.ChosenMove.Value = ""

		local Player1 = game.Players:GetPlayerFromCharacter(Corners[1].Occupant.Value)
		local Player2 = game.Players:GetPlayerFromCharacter(Corners[2].Occupant.Value)

		-- Update Player1's UI
		Player1.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
		Player1.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value

		-- Update Player2's UI
		Player2.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
		Player2.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
	end

	DefendingPlayer.Character.Humanoid.Health = 0
	AttackingPlayer.Character.HumanoidRootPart.Anchored = false
	AttackingPlayer.Backpack.Data.State.Value = ""
	DefendingPlayer.Backpack.Data.State.Value = ""
	AttackingPlayer.Backpack.Data.Ring.Value = nil
	DefendingPlayer.Backpack.Data.Ring.Value = nil
	Attacker.Value = nil
	Defender.Value = nil
	Billboard.TextLabel.Text = Occupants.. "/2"
	for i, v in pairs(Corners) do
		v.Occupant.Value = nil
	end
	Occupants = 0
end

PP.Triggered:Connect(function(Player)
	local Found = false
	for i, v in pairs(Corners) do
		if v.Occupant.Value == Player.Character then
			Found = true
		end
	end
	if Found then return end
	Player.PlayerGui.ShadowBoxing.LeaveMatch.Visible = true
	Occupants = Occupants + 1
	local Corner = Corners[1]

	if Corner.Occupant.Value ~= nil then
		Corner = Corners[2]
	end
	Corner.Occupant.Value = Player.Character
	Player.Backpack.Data.Ring.Value = script.Parent

	Billboard.TextLabel.Text = Occupants.. "/2"

	-- This will fire only once.
	Player.Character.Humanoid.Died:Once(function()
		-- Check if the player is still the occupant.
		if Corner.Occupant.Value == Player.Character then
			Corner.Occupant.Value = nil
			Player.PlayerGui.ShadowBoxing.LeaveMatch.Visible = false -- Hide the button when the player dies.
		end
	end)

	if Occupants == 2 then
		coroutine.wrap(function()
			wait(1)
			Billboard.Enabled = false
		end)()
		PP.Enabled = false
		local RandomNumber = math.random(1,2)
		Attacker.Value = Corners[RandomNumber].Occupant.Value
		Defender.Value = Corners[((RandomNumber == 1) and 2) or 1].Occupant.Value

		game.ReplicatedStorage.Client.Countdown:FireClient(game.Players:GetPlayerFromCharacter(Attacker.Value))
		game.ReplicatedStorage.Client.Countdown:FireClient(game.Players:GetPlayerFromCharacter(Defender.Value))
		wait(3)
		StartFight()
		wait(1)
		PP.Enabled = true
		Billboard.Enabled = true
	end
end)

for i, v in pairs(Corners) do
	v.Occupant.Changed:Connect(function()
		if not v.Occupant.Value then
			Occupants -= 1
			Billboard.TextLabel.Text = Occupants .. "/2" -- Here
			return
		end
		local Char = v.Occupant.Value
		local Hrp:Part = Char:FindFirstChild("HumanoidRootPart")
		if not Hrp then return end
		Char.Humanoid.WalkSpeed = 0
		Hrp.AssemblyLinearVelocity = Vector3.new()
		Hrp.CFrame = v.CFrame
		Hrp.Anchored = true
		wait()
		Char.Humanoid.WalkSpeed = 16
	end)

end


Event.OnServerEvent:Connect(function(Player)
	Player.PlayerGui.ShadowBoxing.LeaveMatch.Visible = false

	for _, i in ipairs(Corners) do
		if i.Occupant.Value == Player.Character then
			i.Occupant.Value = nil
			Player.Character.HumanoidRootPart.Anchored = false
			return
		end
	end
end)

Try this, without checking Corners:

-- Wait until both the players input something, or one leaves the game.
repeat task.wait() until not (DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value) or ((AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= ""))

-- Checks if player leaves the ring
local hasPlayers = DefendingPlayer and AttackingPlayer and Defender.Value and Attacker.Value

No more error, back to the print statement, it printed squiggle brackets
image

or something did lol (characters), nvm it printed false im dumb

It printed false before leaving?

It didnt print when I left, it printed false when I chose up and the other chose down

Try replacing the StartFight() function this:

local function StartFight()
	local fight = coroutine.create(function()
		local AttackingPlayer:Player = game.Players:GetPlayerFromCharacter(Attacker.Value)
		local DefendingPlayer:Player = game.Players:GetPlayerFromCharacter(Defender.Value)

		AttackingPlayer.Backpack.Data.CurrentLives.Value = 20
		DefendingPlayer.Backpack.Data.CurrentLives.Value = 20

		game.ReplicatedStorage.Client.ChangeIcons:FireClient(AttackingPlayer, DefendingPlayer.UserId)
		game.ReplicatedStorage.Client.ChangeIcons:FireClient(DefendingPlayer, AttackingPlayer.UserId)

		local Switch = false
		local Rows = {}
		while (DefendingPlayer.Backpack.Data.CurrentLives.Value > 0) do		
			if Switch then
				local TempPlayer = AttackingPlayer
				AttackingPlayer = DefendingPlayer
				DefendingPlayer = TempPlayer
				Switch = false
			end

			AttackingPlayer.Backpack.Data.State.Value = "Attack"
			DefendingPlayer.Backpack.Data.State.Value = "Defend"

			-- Wait until both the players input something, or one leaves the game.
			repeat task.wait() until (AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= "")

			local AttackerChose = AttackingPlayer.Backpack.Data.ChosenMove.Value
			local DefenderChose = DefendingPlayer.Backpack.Data.ChosenMove.Value

			print("Attacker Chose", AttackerChose)
			print("Defender Chose", DefenderChose)
			local PlayedAnimation = false
			if AttackerChose == DefenderChose then
				print("Defender Loses a life, Total:", DefendingPlayer.Backpack.Data.CurrentLives.Value)
				DefendingPlayer.Backpack.Data.CurrentLives.Value -= 1

				print(Rows)
				table.insert(Rows, DefendingPlayer.Backpack.Data.ChosenMove.Value)
				for i, v in pairs(Rows) do
					PlayedAnimation = true
					AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
					DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
					wait(0.5)
				end
				if #Rows == 3 then
					DefendingPlayer.Backpack.Data.CurrentLives.Value = 0
				end
				game.ReplicatedStorage.Client.HideButton:FireClient(AttackingPlayer, "Attack", AttackerChose)
				game.ReplicatedStorage.Client.HideButton:FireClient(DefendingPlayer, "Defend", DefenderChose)
			else
				for i, v in pairs(Rows) do
					AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
					DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
					wait(0.5)
				end

				Rows = {}
				Switch = true
			end
			if not PlayedAnimation then
				AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..AttackingPlayer.Backpack.Data.ChosenMove.Value]):Play()
				DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..DefendingPlayer.Backpack.Data.ChosenMove.Value]):Play()
			end

			wait(1)
			AttackingPlayer.Backpack.Data.ChosenMove.Value = ""
			DefendingPlayer.Backpack.Data.ChosenMove.Value = ""

			local Player1 = game.Players:GetPlayerFromCharacter(Corners[1].Occupant.Value)
			local Player2 = game.Players:GetPlayerFromCharacter(Corners[2].Occupant.Value)

			-- Update Player1's UI
			Player1.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
			Player1.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value

			-- Update Player2's UI
			Player2.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
			Player2.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
		end

		DefendingPlayer.Character.Humanoid.Health = 0
		AttackingPlayer.Character.HumanoidRootPart.Anchored = false
		AttackingPlayer.Backpack.Data.State.Value = ""
		DefendingPlayer.Backpack.Data.State.Value = ""
		AttackingPlayer.Backpack.Data.Ring.Value = nil
		DefendingPlayer.Backpack.Data.Ring.Value = nil
		Attacker.Value = nil
		Defender.Value = nil
		Billboard.TextLabel.Text = Occupants.. "/2"
		for i, v in pairs(Corners) do
			v.Occupant.Value = nil
		end
		Occupants = 0
	end)

	game.Players.PlayerRemoving:Once(function(Player)
		if Player == AttackingPlayer or Player == DefendingPlayer then
			Attacker.Value = nil
			Defender.Value = nil	

			for i, v in pairs(Corners) do
				if v.Occupant.Value ~= nil then
					local player = game.Players:GetPlayerFromCharacter(v.Occupant.Value)

					v.Occupant.Value.HumanoidRootPart.Anchored = false
					player.Backpack.Data.State.Value = ""
					player.Backpack.Data.Ring.Value = nil		
				end

				v.Occupant.Value = nil
			end

			Occupants = 0
			Billboard.TextLabel.Text = "0/2"

			coroutine.close(fight) -- This should basically stop the fight loop.
		end
	end)

	coroutine.resume(fight)

	repeat task.wait() until fight.status == "dead" -- Don't continue until the fight loop ends.
end

Error Workspace.Ring.MainRing:138: attempt to index thread with 'status' - Server - MainRing:138

repeat task.wait() until fight.status == "dead" -- Don't continue until the fight loop ends.

Try replacing that line with

repeat task.wait() until coroutine.status(fight) == "dead" -- Don't continue until the fight loop ends.
1 Like

Still nothing, would it be easier if I gave you the file?

It would probably be so much easier.

Alright here you go! So the dying and them still in the game ofc, but is it possible to add barriers so people cant jump on to the ring when a match has started?

Ring.rbxl (109.3 KB)

Here is your ring. I have fixed some bugs, and added the barriers you wanted.

Ring.rbxl (110.4 KB)

Sweet thank you dude it works like a charm! One last thing it should be pretty easy I just suck at scripting, but could you help me with this. So I have found a confetti module and I want to have it so if you buy a gamepass or dev product, the confetti shoots up, could you help me with that?
Confetti.rbxl (54.7 KB)

Oh and also whenever you click leave, the barriers are still their

I didn’t really understand what you needed, but I did something with the confetti. So when you click the button, confetti comes out.

Confetti.rbxl (54.8 KB)

1 Like

We’re you able to fix the barrier issue where if they try to leave the match the barriers go away