Function not firing, please help

This is code for a wait in line game, the premise is when you make it to the front in line, you fight your opponent who was the previous winner (or next in line if the game is just starting) but for some reason the function isn’t firing, im not sure what i did wrong.

this is the part of the script that i think is bugging in my main server:

local function startFightTimer()
	if #PlayersInArena < MaxPlayersInArena then
		FightUIEvent:FireAllClients(0, "waiting_for_opponent") --tells ui to wait
		warn("not enough players to start the fight") -- debugging
		return -- Doesn't start if there aren't two players
	end

	print("fight started! Players have 30 seconds.") -- debugging

	-- fire ui event
	FightUIEvent:FireAllClients(30, "fight start")
	print("FightUIEvent fired for fight start") -- debugging

	local fightDuration = 30
	while fightDuration > 0 do
		FightUIEvent:FireAllClients(fightDuration, "fight timer")
		print("Timer: " .. fightDuration .. " seconds") --debugging
		task.wait(1) -- Wait 1 second per loop
		fightDuration -= 1
	end
	
	-- fight ended
	print("Fight over!") --debugging

	--check which players are still alive and determine winner
	local alivePlayers = {}

	for _, player in pairs(PlayersInArena) do
		if player and player.Character and player.Character:FindFirstChild("Humanoid") then
			if player.Character.Humanoid.Health > 0 then
				table.insert(alivePlayers, player)
			end
		end
	end	
	
	-- handle victory or draw
	local winner = nil
	if #alivePlayers == 1 then
		winner = alivePlayers[1]
		winner.Character.Humanoid.Health = winner.Character.Humanoid.MaxHealth -- restore health
		print("🏆 " .. winner.Name .. " wins the fight!") -- Debugging
		FightUIEvent:FireAllClients(0, "winner", winner.Name)
		
		
		--give the winner a leaderboard win
		winner.leaderstats.Wins.Value = winner.leaderstats.Wins.Value + 1
	else
		print("🥶 Draw!") -- Debugging
		FightUIEvent:FireAllClients(0, "draw")
	end
	
	--send loser to the end of the line
	local newPlayersInArena = {}
	if #alivePlayers == 1 then
		local winner = alivePlayers[1]
		table.insert(newPlayersInArena, winner) -- keep the winner in the arena
	end
	
	PlayersInArena =  newPlayersInArena -- only winner stays
	
	for _, player in pairs(PlayersInArena) do
		if player ~= winner then -- send the loser back in line
			local lastTileNumber = #ActiveTilesFolder:GetChildren()
			local lastTile = ActiveTilesFolder:FindFirstChild(tostring(lastTileNumber))
			
			if lastTile then
				playerTiles[player.UserId] = lastTile
				moveToTile(player, lastTile)
				print(player.Name .. " was sent to the end of the line.")
			end
		end
	end
	
	PlayersInArena = newPlayersInArena --reset arena
	
	--check if there's an available player to fight the winner
	for _, player in pairs(Players:GetPlayers()) do
		if not table.find(PlayersInArena, player) then
			if #PlayersInArena < MaxPlayersInArena then
				moveToTile(player, ArenaTile) --bring in the next player
				print(player.Name .. " is joining the arena.")
				break
			end
		end
	end
end

and this is the timer UI for the fight, it’s supposed to announce the fight the winner and the time in the fight left:

FightUIEvent.OnClientEvent:Connect(function(timeLeft, eventType, winnerName)
	print("✅ FightUIEvent received:", eventType, " Time:", timeLeft, " Winner:", winnerName or "None") -- Debugging
	
	
	if eventType == "fight_start" then
		inLine.Enabled = false --disable ui
		local backInLineButton = playerGui:WaitForChild("OutLine"):WaitForChild("Main"):WaitForChild("Bottom"):WaitForChild("Buttons"):WaitForChild("PLAY")
		backInLineButton.Visible = false
		outLine.Enabled = false
		FightTimerUI.Enabled = true -- shows the fight timer
		print("✅ UI Updated: Waiting for Opponent..") -- Debugging
	elseif eventType  == "waiting_for_opponent" then
		FightTimerUI.Enabled =  true
		TimerLabel.Text = "Waiting for opponent.."
	elseif eventType == "fight_timer" then
	TimerLabel.Text = "Timer: " .. timeLeft .. " seconds"
	elseif eventType == "winner" or eventType == "draw" then
		TimerLabel.Visible = false
		WinnerLabel.Text = winnerName .. " Wins!"
		WinnerLabel.Visible = true
		wait(5)
		WinnerLabel.Visible = false
		inLine.Enabled = true -- allow player to reenter queue
	elseif eventType == "draw" then
		TimerLabel.Visble = false
		WinnerLabel.Text = "DRAW!"
		WinnerLabel.Visible = true
		wait(5)
		WinnerLabel.Visible = false
		inLine.Enabled = true -- allow player to reenter queue
	end
end)	

Did it print or warn anything?

it doesnt seem like youre even calling the function. could you provide the code where you call it?

no no prints or warnings that lead to a solution i can post the output but most of the prints don’t move towards a solution:

20:48:44.349 KaoCr8 added to fight queue. - Server - MainServer:246
20:48:44.919 :arrow_forward: {…} - Server - MainServer:41
20:48:44.919 KaoCr8 movement locked! - Server - MainServer:214
20:48:44.920 KaoCr8 assigned tile: 1 - Server - MainServer:323
20:48:44.920 Assigned tile to player: KaoCr8 Tile: 1 - Server - MainServer:326
20:48:44.920 :arrow_forward: {…} KaoCr8 1 - Server - MainServer:77
20:48:45.002 :white_check_mark: UIHandler script loaded - Client - UIHandler:56
20:48:45.037 bound - Client - FreezePlayer:61
20:48:56.346 player has a sword - Server - MainServer:595
20:48:56.347 KaoCr8 has been given a sword - Server - MainServer:598
20:48:56.347 ClassicSword - Server - MainServer:599
20:48:56.383 unbound - Client - FreezePlayer:65
20:48:56.782 PlayerGui Child: Freecam - Client - UIHandler:256
20:48:56.782 PlayerGui Child: OutLine - Client - UIHandler:256
20:48:56.782 PlayerGui Child: InLine - Client - UIHandler:256
20:48:56.782 PlayerGui Child: Scripts - Client - UIHandler:256
20:48:56.783 PlayerGui Child: Nuke - Client - UIHandler:256
20:48:56.783 PlayerGui Child: FightTimerUI - Client - UIHandler:256

I have it called in a script above it for when the player gets teleported to the EndTP (which is the arena)

‘’'lua
endFunction.OnServerInvoke = function(player: Player)
local EndTP = workspace:WaitForChild(“EndTP”)
local character = player.Character or player.CharacterAdded:Wait()

if character and EndTP and character:FindFirstChild("HumanoidRootPart") then
	character:PivotTo(EndTP.CFrame)
	
	
	local function giveSword(player)
		for _, item in player.Backpack:GetChildren() do
			if item:IsA("Tool") and item.Name == "ClassicSword" then
				return -- Player already has a sword
		end
	end
end
	
	--give player sword
	local sword = replicatedStorage:FindFirstChild("ClassicSword")
	if sword then
		print("player has a sword") -- debugging
		local clonedSword = sword:Clone()
		clonedSword.Parent = player.Backpack
		print(player.Name.. " has been given a sword") -- debugging
		print(clonedSword)
	else
		warn("⚠️ ClassicSword not found in ReplicatedStorage!") -- Debugging
	end

	stopGivingMoney(player)
	playerTiles[player.UserId] = nil
	moveAllUp()

	removeLastTile()
	freezePlayer:FireClient(player, false)
	
	startFightTimer()

	return true
end

return false

end
‘’’

its above the startfightimer() function so I’m not sure if it would make a difference to paste the startfighttimer above the other function

i was about to mention this. you should try rearranging the functions perhaps. actually, it only matters if it is being called before the startFightTimer definition. could you add a print statement right before start fight timer and see if it runs

local function startFightTimer()
print(“StartFightTimer is Running Properly”)
if #PlayersInArena < MaxPlayersInArena then
FightUIEvent:FireAllClients(0, “waiting_for_opponent”) --tells ui to wait
warn(“not enough players to start the fight”) – debugging
return – Doesn’t start if there aren’t two players
end

this didn’t work and the print statement didn’t work
print(“StartFightTimer is Running Properly”)

rearranging the functions actually made the function get called and the print statement ran, there’s still some glitches i have to fix since the start fight timer isn’t actually working nor is it preventing only 2 players from being able to join at a time but i think I can problem solve from here

ok good luck!

char limit char limit char limit