I thought this would be a simple tutorial that requires relatively little scripting knowledge.
For one, you’re going to want a list of two types of death messages, suicides and PvP. I’ll provide some here if you need one.
Then you’re going to need a remote event in ReplicatedStorage, which will pass the message over to the client.
--Put this in a script in StarterCharacterScripts.
local suicideMessages = {"%s died.", "%s is dead.", "%s flatlined."};
local pvpMessages = {"%s killed %s.", "%s murdered %s.", "%s destroyed %s.", "%s ruined %s."};
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local random = Random.new();
local deathMessageEvent = ReplicatedStorage.DeathMessage;
local char = script.Parent;
local hum = char:FindFirstChildOfClass("Humanoid");
function onDeath()
--killerName doesn't have to be an attribute, but for this method, it has to be a string.
local killerName = hum:GetAttribute("killer");
local victimName = hum.DisplayName;
local deathMessage;
if killerName and killerName ~= victimName then --If a player killer this person, and it wasn't themselves.
--This will get a random entry from pvpMessages.
deathMessage = pvpMessages[random:NextInteger(1, #pvpMessages)];
--Then we use string.format() to replace those '%s' with the killerName and victimName.
deathMessage = string.format(deathMessage, killerName, victimName);
else --If it was a suicide.
--This will get a random entry from suicideMessages.
deathMessage = suicideMessages[random:NextInteger(1, #suicideMessages)];
--Then formats like we did above, but with just the victimName.
deathMessage = string.format(deathMessage, victimName);
end
deathMessageEvent:FireAllClients(deathMessage);
end
hum.Died:Connect(onDeath);
--Then put this in a LocalScript.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local StarterGui = game:GetService("StarterGui");
local deathMessageEvent = ReplicatedStorage:WaitForChild("DeathMessage");
function onDeathMessage(message)
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = message; --Sets the message to be, well, the message.
Color = Color3.fromRGB(255, 0, 0); --Makes the text appear in red.
Font = Enum.Font.SourceSansBold; --Change this if you'd like, but this is the default.
TextSize = 18; --You can also change this if you'd like.
}); --This function displays a message in the chat, the text, color, font, and size can be changed.
end
deathMessageEvent.OnClientEvent:Connect(onDeathMessage);
This whole thing mainly revolves around StarterGui:SetCore() function. This can do more than just make chat messages, you can disable character resetting, send a notification, and more. You can see the rest here.
If you’re a more experienced programmer, you could even make different messages depending on how the player dies! Maybe I’ll update this with a guide on how to do that if anyone would like that.
Thanks for reading!