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