Multiple points being added for deaths?

function deathmatch:Gamemode()
	
	configuration.BLUE_SCORE = 0
	configuration.RED_SCORE = 0
	
	updateScore:FireAllClients(configuration.BLUE_SCORE, configuration.RED_SCORE)
	
	local start = coroutine.create(function()
	    for _, player in pairs(players:GetPlayers()) do
			player.CharacterRemoving:Connect(function(character)
				if player.Team == teams.Blue then
					configuration.RED_SCORE = configuration.RED_SCORE + 1
				elseif player.Team == teams.Red then
					configuration.BLUE_SCORE = configuration.BLUE_SCORE + 1
				end
				
				updateScore:FireAllClients(configuration.BLUE_SCORE, configuration.RED_SCORE)
				
				if configuration.BLUE_SCORE == configuration.DEATHMATCH_SCORE or configuration.RED_SCORE == configuration.DEATHMATCH_SCORE then
					timeManager:End()
				end
			end)
		end
	end)
	
	coroutine.resume(start)
	
	timeManager:StartTimer(configuration.DEATHMATCH_TIME, true)
end

Here’s my deathmatch gamemode module. Simply is required when the gamemode has to start. Has a coroutine to run the death counter and still enable the time manager to manage the countdown timer.

Problem I am facing is on occasion teams may be rewarded with multiple points on a player death. Sometimes even up to 10 points! Reason why I am using CharacterRemoving was because I was having problems with the DIed function not working at all.

Could you add a debounce when the character is removed, And then remove the debounce when the character spawns again?

Still occurs :confused:

Did you try something like this?:

function deathmatch:Gamemode()
	
	configuration.BLUE_SCORE = 0
	configuration.RED_SCORE = 0
	
	updateScore:FireAllClients(configuration.BLUE_SCORE, configuration.RED_SCORE)
	
	local debounces = {}
	
	local start = coroutine.create(function()
	    for _, player in pairs(players:GetPlayers()) do
			player.CharacterRemoving:Connect(function(character)
				if not debounces[player.UserId] then
					debounces[player.UserId] = true
					if player.Team == teams.Blue then
						configuration.RED_SCORE = configuration.RED_SCORE + 1
					elseif player.Team == teams.Red then
						configuration.BLUE_SCORE = configuration.BLUE_SCORE + 1
					end
					
					updateScore:FireAllClients(configuration.BLUE_SCORE, configuration.RED_SCORE)
					
					if configuration.BLUE_SCORE == configuration.DEATHMATCH_SCORE or configuration.RED_SCORE == configuration.DEATHMATCH_SCORE then
						timeManager:End()
					end
				end
			end)
			player.CharacterAdded:Connect(function(character)
				if debounces[player.UserId] then
					debounces[player.UserId] = nil
				end
			end)
		end
	end)
	
	coroutine.resume(start)
	
	timeManager:StartTimer(configuration.DEATHMATCH_TIME, true)
end
1 Like

I shall test it out now :+1:

Just looking though, pretty sure CharacterAdded is redundant, as CharacterRemoving fires when the character has been re-added

From the posted code it seems like you never clean up the connections, so a player that plays multiple rounds would have multiple connections.

The coroutine doesn’t do anything in this case, you’re just complicating it.

Ahh, would make sense as to why the numbers gradually got higher

Still does it :confused:

It seems to go like this:

First round: works perfectly, only gives 1 point.

Second round: gives out 2 points per death

Third round: gives out 3 points per death

Fourth round: … youcan probably guess the pattern from here… :confused:

You might need to store the connection for the events so you can disconnect them after they are not needed.

How would I do that?

https://developer.roblox.com/api-reference/datatype/RBXScriptSignal
https://developer.roblox.com/api-reference/datatype/RBXScriptConnection

local con = {}

con[#con+1] = player.CharacterRemoving:Connect(...)

-- round end
for i=1, #con do
    con[i]:Disconnect()
    con[i] = nil -- remove from table
end
3 Likes