-
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
-
, atm it’s only updating the ui texts to only the killer when it should show for all players.
-
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)