How would I go about making a global kill feed?

Hey devs,

How would I go about creating a global kill feed? I already have a live kill feed that tracks kills in your server and displays them in a board. I am trying to make a separate board that will show the kills happening throughout all of the servers.

This is my code for the local one:

local function getPlayerImage(player)
	local ImageSize = Enum.ThumbnailSize.Size420x420
	local ImageType = Enum.ThumbnailType.HeadShot

	local success, imageUrl = pcall(function()
		return game.Players:GetUserThumbnailAsync(player.UserId, ImageType, ImageSize)
	end)

	if success then
		return imageUrl
	else
		warn("Failed to get image for player: " .. player.Name)
		return ""
	end
end


local function updateKillFeed(killedName, killerName, auraStolen)
	if killedName and killerName and auraStolen then
		local template = workspace.KillFeed.SurfaceGui.Frame.Template
		if template then
			local killedPlayer = game.Players:FindFirstChild(killedName)
			local killerPlayer = game.Players:FindFirstChild(killerName)

			local newTemplate = template:Clone()
			newTemplate.Parent = workspace.KillFeed.SurfaceGui.Frame
			newTemplate.Visible = true
			
			local newAura = if killedPlayer:FindFirstChild("InKillerZone") and killerPlayer:FindFirstChild("InKillerZone") then auraStolen else auraStolen / 2
			
			newTemplate.Message.Text = killerName.." stole "..tostring(newAura).." from "..killedName
			newTemplate.KilledImg.Image = getPlayerImage(killedPlayer)
			newTemplate.KillerImg.Image = getPlayerImage(killerPlayer)
			newTemplate.LayoutOrder = -1

			coroutine.wrap(function()
				task.wait(5)
				newTemplate:Destroy()
			end)()
		end
	end
end

Thanks a lot devs :slight_smile:

-DarkPurpleElixr

1 Like

You can use the MessagingService’s SubscribeAsync and PostAsync methods to send messages between servers.

I implemented what you said with this code:

local function sendKillEventToGlobalFeed(killedPlayer, killerPlayer, auraStolen)
	local killedInZone = killedPlayer:FindFirstChild("InKillerZone") ~= nil
	local killerInZone = killerPlayer:FindFirstChild("InKillerZone") ~= nil

	local killEvent = {
		killedName = killedPlayer.Name,
		killerName = killerPlayer.Name,
		auraStolen = auraStolen,
		killedInZone = killedInZone,
		killerInZone = killerInZone
	}

	print("Sending Kill Event:", killEvent.killerName, "stole", killEvent.auraStolen, "from", killEvent.killedName)

	local success, errorMessage = pcall(function()
		MessagingService:PublishAsync(KILL_FEED_TOPIC, killEvent)
	end)

	if not success then
		warn("Failed to publish kill event: " .. errorMessage)
	else
		print("Kill event published successfully")
	end
end




local function updateGlobalKillFeed(killEvent)
	print("Updating Global Kill Feed with event:", killEvent.killerName, "stole", killEvent.auraStolen, "from", killEvent.killedName)

	local killedName = killEvent.killedName
	local killerName = killEvent.killerName
	local auraStolen = killEvent.auraStolen
	local killedInZone = killEvent.killedInZone
	local killerInZone = killEvent.killerInZone

	local template = workspace.GlobalKillFeed.SurfaceGui.Frame.Template
	if template then
		local newTemplate = template:Clone()
		newTemplate.Parent = workspace.GlobalKillFeed.SurfaceGui.Frame
		newTemplate.Visible = true

		local newAura = if killedInZone and killerInZone then auraStolen else auraStolen / 2

		newTemplate.Message.Text = killerName .. " stole " .. tostring(newAura) .. " from " .. killedName
		newTemplate.LayoutOrder = -1

		coroutine.wrap(function()
			task.wait(5)
			newTemplate:Destroy()
		end)()
	else
		warn("Kill feed template not found")
	end
end


local function onMessageReceived(message)
	print("Message received from global kill feed")
	local killEvent = message.Data
	updateGlobalKillFeed(killEvent)
end


local success, errorMessage = pcall(function()
	MessagingService:SubscribeAsync(KILL_FEED_TOPIC, onMessageReceived)
end)

if not success then
	warn("Failed to subscribe to global kill feed: " .. errorMessage)
else
	print("Successfully subscribed to global kill feed")
end

And yet nothing is showing up on the billboard GUI.

Prints:
11:59:18.293 Successfully subscribed to global kill feed - Server - leaderstats:270
12:00:36.607 Sending Kill Event: Player1 stole 1847 from Player2 - Server - leaderstats:210
12:00:36.640 Kill event published successfully - Server - leaderstats:219