Help with a leaderstats GUI

I am trying to make a team deathmatch game, and my gui for the kill score has been having issue, I have made it so that it does individual leaderstats. Is there a way to make it so that it use team stats (The number next to the team name which is all scores added up.)

This is my current local script for the GUI.

while wait(1) do
	script.Parent.Text = "Kills : "..game.Players.LocalPlayer.leaderstats.Kills.Value
end

I am very new to scripting so I have tried youtube tutorials and I can’t find anything.

You should use…

game.Players.LocalPlayer.leaderstats.Kills.Changed:Connect(function()
    script.Parent.Text = "Kills : "..game.Players.LocalPlayer.leaderstats.Kills.Value
end)

I had originally watched a tutorial to get the first script.

What do you mean by that? It seems that you want to make a UI that displays a player’s current kills.

I originally had, but I was confused how to make it work for teams current kills.

You will have to use Team:GetPlayers()
https://developer.roblox.com/en-us/api-reference/function/Team/GetPlayers

to get a list of players for that team and then add up all their score values.

There used to be a way to do this directly with Team.Score
https://developer.roblox.com/en-us/api-reference/property/Team/Score
but it has been depricated and should not be used for new work.

Also please take note that a lot of tutorials out there are either outdated or just simply dont use the correct way to do things with optimization in mind.

Avoid using loops whenever possible by replacing things with event based connections.

Thank you so much, I was thinking I would have to add them up, but wasnt sure if there was a way to get it immediatly.
Thanks again.

1 Like

Use :GetPropertyChangedSignal

game.Players.LocalPlayer.leaderstats.Kills:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = "Kills : "..game.Players.LocalPlayer.leaderstats.Kills.Value
end)
1 Like