ShouldDeliverCallback returns multiple times? (TextChatService)

EDIT: After looking into the problem, I did not terminate the timer properly.

Hello,
I am making a skribbl. io (draw and guess) type game and it uses the new TextChannel service to prevent other players from seeing the word (if the guess matches the word). My issue here is that the callback runs multiple times (based on how many players are in the server), while I only want it to run once. How can i fix this? I’ve tried using a debounce, but it only seemed like a band-aid solution.

two players were in this server.
image

My Code

generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)
	if WordHandler.chosenWord ~= nil and string.match(string.lower(textChatMessage.Text), string.lower(WordHandler.getChosenWord())) then
			local playerObject = Players:GetPlayerByUserId(textChatMessage.TextSource.UserId) 
			local playerName = textChatMessage.TextSource.Name
			if playerObject:GetAttribute("guessed") then
				return false
			end
			guessedSFX:Play()
			playerObject:SetAttribute("guessed", true)
			serverMessage:FireAllClients(playerName .. " guessed the word!")
			local count = 0
			for i, v in ipairs(Players:GetPlayers()) do
				if v:GetAttribute("guessed") then
					count += 1
				else
					continue
				end
			end
			if count == #Players:GetPlayers() - 1 then
				RoundHandler.endRound()
				print("enough players have guessed")
			end
		return false
	else
		return true
	end
end

You asked the script if the player (v) has the attribute “guessed” not if the attribute it’s value is true. :stuck_out_tongue_winking_eye:
As result every player passes the if statement.

1 Like

EDIT: there was a problem with my timer :sweat_smile:

Hey,
thanks for the reply. Unfortunately, that did not fix my issue.

Here is what I am getting along with the 2 server messages (so i think its because the callback runs based on player count)
image
My endRound function has a warn() statement that essentially tells me the round is over and the builder has changed. I think its because I don’t really know how callbacks work or something :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.