Delete message on send using OnServerReceivingMessage

I’m trying to stop a message from being sent if a specific condition is met but it isn’t working. My print statements do log properly but nothing happens to the message.

Code:

Chat:RegisterChatCallback(Enum.ChatCallbackType.OnServerReceivingMessage, function(message)
    print('message sent')
	print(message)
	local player = game.Players:GetPlayerByUserId(message.SpeakerUserId)
	local trasmitting = player.PlayerGui.Police.Radio.CheckTransmitting:InvokeClient(player)
	if player.Team.Name == 'PD' and trasmitting then
		print('deleting message')
		message.ShouldDeliver = false
		return message
	end
end)

I think the main problem would be the delay here

I’m not sure, but there may be some timeout on the callback in case nothing is returned and the game wants the chat to be sent fast. Try setting transmitting to true automatically and removing the InvokeClient to see if it works.

Hm, that did work. Will using a value stored in the player rather than a RemoteFunction eliminate this delay?

I believe having the client send a value to the server every time they start/end transmitting and the server storing that value somewhere inside the player will work as it won’t have any delays getting it.

Yep, thats what I ended up doing and it works fine. Thanks!

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