Help with FireClient Error

What’s going on is that the leave button doesn’t do anything until the fight starts.
To fix this problem, try to put the code at the bottom of the script. This way, the script can reach it before the fight starts.

1 Like

When I put it at the very end, nothing seems to show up

Try adding a line to unanchor the player’s HumanoidRootPart when leaving, like this:

Event.OnServerEvent:Connect(function(Player)
	for _, i in ipairs(Corners) do
		if i.Occupant.Value == Player.Character then
			i.Occupant.Value = nil
			Player.Character.HumanoidRootPart.Anchored = false
			Player.PlayerGui.ShadowBoxing.LeaveMatch.Visible = false -- This needs to be false.
			return
		end
	end
end)

Here shows the button when the player joins.

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 -- Shows the button after entering

So it makes me unacnchored but the tic still says 1/2
image

You can fix this by adding this line to this part of the script:

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

Sweet it works! One thing is when a player resets or leaves i think it still shows 1/2 even tho hes gone

I’m sure when the player leaves, the character gets destroyed. But you can fix the reset problem by adding some lines of code here:

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
	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)

I just tested if the player’s character is destroyed after death. Apparently, it doesn’t.

Its giving me an error on the Event


Nvm I fixed it, but the Leave button now doesnt show up

Did you replace the entire code? It should be like this:

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 -- Shows the button after entering
	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)

So it shows but when I click it, it stays lol

It might be becuase the Visible value is being set on the client, and stays that way.
Try removing this line from the LocalScript, because it’s already being set on the server.

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Visible = false -- This line here
	yourRemoveEvent:FireServer()
end)

Oh it is? When I removed it and made it visible it stayed visible even when i left

Is the LocalScript parented to the button?

Yes, here is the local script

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


script.Parent.MouseButton1Down:Connect(function()
	Event:FireServer()
end)

Over here, when the server receives the message, try this:

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)

This should set the visibility of LeaveMatch to false, even if the player isn’t in the ring.

Sweet it works, is there anyway I can display the amount of lives the players have to the player 1 or 2?
image

wait so now when 2 players join it just doesnt work. Like the game doesnt work

You mean the game doesn’t start?

Yeah like the countdown then the game doesnt work