You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want a system message to appear when a player runs a command, showing whether it succeeded.
What is the issue? Include screenshots / videos if possible!
The system message appears before the chat message that called the command.
What solutions have you tried so far? Did you look for solutions on the Developer Hub? wait()works, but I’m looking for a better/nicer way. That doesn’t occasionally fail.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
My current setup is:
Players.PlayerAdded →
connect plr.Chatted →
do command →
send result to the user using a RemoteEvent →
display the received result using SetCore()
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
The system message is getting fired before the chat message can show in chat. Try adding a wait before you send the system message. (For around 2-3 seconds, or so.)
Assuming the command always runs before the chat appears, just add this to the local script:
game.Players.LocalPlayer.Chatted:Wait()
Now, I’m pretty sure this should work, but I might be wrong. I’m assuming the local script will actually fire when the chat comes through because the server actually handles the filtering then sends the chat through and the client receives and displays it.
Okay, so I’ve tested myself, and so far I don’t think there is any specific way in order to check when the message actually appears, so the best thing to do would be to add a task.wait() in the local script.
There is no better way… The chat is registering your chat before it can show up, so the system is running before your chat shows up. You need a yield, period.
It may not look the nicest, but it’s what you have to do. Or perhaps you can check when the player dies on the server, fire a remote event, and display the message then.
local Players = game:GetService("Players")
local sendToPlayerEvent = game:GetService("ReplicatedStorage").Events.path.to.event
local function blowupCommand(plr, message)
-- blow all players up
return "Blew up 2/2 players"
end
Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message, recipient)
if message == "/explode all" then
local result = blowupCommand(plr, message)
sendToPlayerEvent:FireClient(plr, result)
end
end)
end)
Client
local StarterGui = game:GetService("StarterGui")
local sendToPlayerEvent = game:GetService("ReplicatedStorage").Events.path.to.event
sendToPlayerEvent.OnClientEvent:Connect(function(result)
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = result
})
end)