Need help showing the updated Texts to all Players not just for the killer?

  1. i’m trying to make it update the information for all players not just for the killer, it’s basically a stud counter but i don’t know how to make it show for everyone

  2. , atm it’s only updating the ui texts to only the killer when it should show for all players.

  3. i tried adding a table of players i tried adding it to update all players PlayerGui StudCounterUI and it still wouldn’t work, here is the code to access the ui though local UI = script.Parent

--script made by jjphariss/Vividstar
--just a quick simple stud counter works with any tool/weapon etc

local Players = game:GetService("Players")

-- References to GUI elements
local Player1Label = script.Parent.Frame.Player1
local Player2Label = script.Parent.Frame.Player2
local StudCounterLabel = script.Parent.Frame.StudCounter


-- Function to calculate distance in studs
local function calculateDistance(point1, point2)
	local distanceVector = point1 - point2
	local distanceStuds = distanceVector.Magnitude / 1.1 --change this to make it more accurate
	return distanceStuds
end


-- Function to update the kill display
local function updateKillDisplay(killer, victim, distance)
	Player1Label.Text = "" .. (killer and killer.Name or "Unknown")
	Player2Label.Text = "" .. (victim and victim.Name or "Unknown")
	StudCounterLabel.Text = string.format("Distance: %.0f studs", distance)
end

-- Function to reset the GUI
local function resetDisplay()
	Player1Label.Text = ""
	Player2Label.Text = ""
	StudCounterLabel.Text = ""
end

-- Listen for player deaths
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local killer = nil
			local victim = player

			-- Determine the killer
			local characterRootPart = character:WaitForChild("HumanoidRootPart")
			local characterParts = character:GetDescendants()
			local distance = math.huge

			for _, otherPlayer in ipairs(Players:GetPlayers()) do
				if otherPlayer ~= player and otherPlayer.Character then
					local otherCharacter = otherPlayer.Character
					local otherCharacterRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
					if otherCharacterRootPart then
						local d = calculateDistance(characterRootPart.Position, otherCharacterRootPart.Position)
						if d < distance then
							distance = d
							killer = otherPlayer
						end
					end
				end
			end

			updateKillDisplay(killer, victim, distance)
			wait(5) -- Display the kill information for 5 seconds
			resetDisplay()
		end)
	end)
end)

1 Like

You can either use Remote Events to send information about the killer to other players, or you can use Data Objects such as Int Value in replicated storage and have clients detect changes via the Change event.

1 Like

i tried that already and it did work but it was only showing to the victim i killed only when they respawned. it’s showing in such a late way. so i gave up lol idk why it’s even doing that even with using the other methods mentioned.