Leaderboard Scripting wins

The issue is that basically, if a player survives 5 rounds of a game they are suppose to get a win. For some reason its not awarding the surviving players any wins. I’ve tried putting the rounds down to round 4 to see if the issue is the script or the rounds and the issue is surely the script. Any help is appreciated thank you.

local function AwardWinIfMinnowStillAlive(currentSubRound) if currentSubRound == 5 then for _, player in ipairs(game.Players:GetPlayers()) do if player.Team and player.Team.Name == "Minnows" then AwardWin(player) print(player.Name .. " has won the round!") end end end end

3 Likes

Check if the team name really is Minnows and the currentSubRound really reached 5. If yes then there could be a problem within the AwardWin(player) function or the call of the AwardWinIfMinnowStillAlive(currentSubRound) function.

2 Likes

did you run AwardWinIfMinnowStillAlive function?

2 Likes

I did yes its a little bit of code but heres where i used it.

`local function startNewRoundTimer()
startTimer(GameConfig.ROUND_TIME, function()
– First, turn any remaining minnows into sharks and check after each one
for _, player in ipairs(Players:GetPlayers()) do
if player.Team and player.Team.Name == “Minnows” and not touchedMinnows[player] then
debugPrint(player.Name … " didn’t make it to safe zone, becoming shark!")
TeamsModule:SetPlayerAsShark(player)
if player.Character then
SharkManager.setupSharkTagging(player.Character)
end

				local anyMinnowsLeft = false
				for _, p in ipairs(Players:GetPlayers()) do
					if p.Team and p.Team.Name == "Minnows" then
						anyMinnowsLeft = true
						break
					end
				end

				
				if not anyMinnowsLeft then
					debugPrint("No minnows left! Sharks win!")
					stopTimer()
					AwardWinToSharks()  -- Award the win to sharks
					task.spawn(startIntermission)
					return
				end
			end
		end

		
		if currentSubRound < 5 then
			currentSubRound = currentSubRound + 1
			GameEvents.Events.RoundUpdate:FireAllClients(currentSubRound)
			currentSafeZoneName, nextSafeZoneName = nextSafeZoneName, currentSafeZoneName
			MapManager.SetCurrentSafeZone(currentSafeZoneName)
			touchedMinnows = {}

			if currentTouchConnection then
				currentTouchConnection:Disconnect()
			end
			local newSafeZone = mapFolder:FindFirstChild(currentSafeZoneName)
			if newSafeZone then
				currentTouchConnection = newSafeZone.Touched:Connect(onSafeZoneTouched)
			end

			startNewRoundTimer()
		else
			
			AwardWinIfMinnowStillAlive(currentRound)

			
			task.wait(3)

			
			startIntermission()
		end
	end)
end

-- Define onSafeZoneTouched after declaring it
onSafeZoneTouched = function(hit)
	if not isTimerRunning then return end 

	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player and player.Team and player.Team.Name == "Minnows" then
		if not touchedMinnows[player] then
			touchedMinnows[player] = true
			debugPrint(player.Name .. " entered safe zone.")

			local allInZone = true
			for _, minnow in ipairs(Players:GetPlayers()) do
				if minnow.Team and minnow.Team.Name == "Minnows" and not touchedMinnows[minnow] then
					allInZone = false
					break
				end
			end

			if allInZone then
				stopTimer()
				if currentSubRound < 5 then
					currentSubRound = currentSubRound + 1
					GameEvents.Events.RoundUpdate:FireAllClients(currentSubRound)
					currentSafeZoneName, nextSafeZoneName = nextSafeZoneName, currentSafeZoneName
					MapManager.SetCurrentSafeZone(currentSafeZoneName)
					touchedMinnows = {}

					if currentTouchConnection then
						currentTouchConnection:Disconnect()
					end
					local newSafeZone = mapFolder:FindFirstChild(currentSafeZoneName)
					if newSafeZone then
						currentTouchConnection = newSafeZone.Touched:Connect(onSafeZoneTouched)
					end

					startNewRoundTimer()
				else
					-- Award wins to remaining minnows at the end of round 5
					AwardWinIfMinnowStillAlive(currentRound)

					-- Start intermission after round 5
					startIntermission()
				end
			end
		end
	end
end`
1 Like

Ya The teams and round count are fine and the award win player is extremely basic but here it is local function AwardWin(player) if player and player:FindFirstChild("leaderstats") then player.leaderstats.Wins.Value += 1 end end

Alright,

but i cant really read your code above like that. Did you paste it in twice?

Ah, no. But now that you say that i accidently put the same line twice i see the issue thanks though.