i have this script that fires commands, and it only runs when a message gets sent (via TextChatService | OnIncomingMessage)
but for some reason, the function gets called twice?
local tChatService = game:GetService("TextChatService")
local rStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
-- Player variables;
local player = players.LocalPlayer
-- Path to events;
local eventsFolder = rStorage:WaitForChild("Events")
local fromClient = eventsFolder:WaitForChild("FromClient")
local commandEvents = fromClient:WaitForChild("Command")
-- Events;
local fireCommand = commandEvents:WaitForChild("FireCommand")
-- Functions;
local function OnIncomingMessage(message: TextChatMessage)
if message.TextSource and message.TextSource.UserId ~= player.UserId then return end
print(`uwu`)
local text = message.Text
if text:sub(1, 1) == "/" then
fireCommand:FireServer(text)
print(`fired remote lol`)
end
end
-- Runtime;
tChatService.OnIncomingMessage = OnIncomingMessage
i am VERY confused, i don’t know what’s going on
i’m not seeing any sort of “double callbacking” in the documentations, so i’m just boldly going to assume that this is some sort of coding error
It’s possible you accidentally have the script running in two places. Try printing the location of the script before firing, see if you get two places.
This is expected behaviour. You can print message.Status and will notice that it will be different both times. It’s just an internal system. Just use message.Status to ensure it fires once.
Essentially, just use this if statement:
if message.Status.Name ~= "Success" then return end
By this logic, we understand that message.Status is important as it allows the developer to know if the message is going to be sent or if it’s already sent or has errored.
I searched about it a bit, noticed a topic mentioning it, tested it myself and that’s it.