Making a K/D Ratio GUI

Currently working on a K/D Gui but coming up against 2 issues depending on how I write the script,
the first variation of the script is:

This works perfectly until you respawn where it no longer works and doesnt change the skd.text

The second is:

And this one works well when you die etc it still displays the K/D but it doesnt seem to update correctly for every player (player1 kills player2, player2’s gui updates to the right KDR but player1’s gui doesnt change) and the number doesnt match up when leaving and rejoining the game

Any help is appreciated

The reason why player 1 doesn’t see the change in player 2’s GUI is because you changed the value of KDR in the client. You should change values in the server. To do this you need a remote event in the replicated storage. Then you need a normal script to the serverscriptservice

Add this to your Local Script

local event = game.ReplicatedStorage:WaitForChild("") ------ name of remote event
deaths.Changed:Connect(function()
	event:FireServer(tonumber(string.format("%.2f", val1 / val2)), KDR)
	
	skd.Text = "K/D: "..tonumber(string.format("%.2f", val1 / val2))
	print("KDR", player, KDR.Value)
end)

Then the code for the Normal Script


local event = game.ReplicatedStorage:WaitForChild("") ------ name of remote event


event.OnServerEvent:Connect(function(player, number, value)
	value.Value = number
end)


Im not trying to make player 1 see the change in player 2 guis (can see where the confusion may come from, not worded the best), the problem is that player2’s gui doesnt change at all (for himself)

Disable ResetOnSpawn then.

However, your function leaks memory by creating a new connection every time Kills is changed. This is wrong for numerous reasons, but here’s what you should’ve done:

local killCount = 0
local deathCount = 0

local function updateRatio()
    -- do stuff with kills and deaths
end

kills.Changed:Connect(function(newKillCount)
    killCount = newKillCount
    updateRatio()
end)

deaths.Changed:Connect(function(newDeathCount)
    deathCount = newDeathCount
    updateRatio()
end)

(Also remember to use descriptive variable names!)