How to measure Team leaderstats

I want to measure up team leaderstats so i can compare the points each team has in a capture the flag game.

thats pretty much all there is to it.

8 Likes

Well that’s very unspecific, anyways you can declare the teams score variable then add to it for every person in the team

4 Likes

Ive already tried making a variable for how much points a team has i just cant figure out how to add each players points to it correctly

4 Likes

Do a for loop with the player’s from each team

local teamPoints
for _,player in pairs( team:GetPlayers()) do
 teamPoints+=player.leaderstats.point.value
end
4 Likes

i put the script in SSS and its not working

local team = game.Teams.North
local teamPoints = team.Value.Value


while wait(1) do
	for _,player in pairs(team:GetPlayers()) do
		teamPoints += player.leaderstats.Points.value
	end
end
4 Likes
local function getTeamPoints(team: Team): number
	local points = 0
	for _, player in pairs(team:GetPlayers()) do
		local ls = player:FindFirstChild("leaderstats")
		if not ls or not ls:FindFirstChild("Points") then continue end
		points += ls.Points.Value
	end
	return points
end

local team = game.Teams.North

while task.wait(1) do
	team.Value.Value = getTeamPoints(team)
end
6 Likes

the script doesnt do anything bugyguh

4 Likes

Are you sure you’re keeping track of points correctly there’s no reason for it to not work

4 Likes

it just doesnt work for some reason but heres another script i tried but it didnt work also

local plr = game.Players.LocalPlayer

while game.StarterGui.TopText.Time.Text == "Deciding Winner..." do
	local team = plr.TeamColor
	if game.Teams.North.TeamColor == team then
		game.Teams.North.Value.Value += plr.leaderstats.Points.Value
		wait(100000)
	end
	if game.Teams.South.TeamColor == team then
		game.Teams.South.Value.Value += plr.leaderstats.Points.Value
		wait(100000)
	end
end

i put this in starterplayerscripts btw

5 Likes

Do you want to measure them at the start of the game or at the end? Or repeatedly?

4 Likes

at the end.,.,…,.,.,.,.,.,…,.,…,.,.,.,/.,/.,./,./,/.,.,/

4 Likes

So. Ill try to help.
You might want to have 2 for loops that iterate over the points of each player in the team, as @uriel_Gamer444 and @NyrionDev did. And you wanna store them in a value. Then do the comparison and set the varìables out yk.

4 Likes

Are you changing Gui text from StarterGui? that doesn’t replicate to clients unless the Gui is reset in the client, you have to change it from game.Players.LocalPlayer.PlayerGui, also wait(100000) will just stop it from ever running again try doing

plr.PlayerGui.TopText.Time:GetPropertyChangedSignal("Text"):Connect(function()--Text got changed
	if plr.PlayerGui.TopText.Time.Text=="Deciding Winner..." then --If the text is that

		if plr.TeamColor==game.Teams.North.TeamColor == team then
			game.Teams.North.Value.Value += plr.leaderstats.Points.Value

		else--Not North team
			game.Teams.South.Value.Value += plr.leaderstats.Points.Value

		end
	end
end)

if you want it to stop from running again you can do a connection and then disconnect it

4 Likes

It didnt change the value.,…,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,

4 Likes

Yeah mb for not mentioning but you’re also trying to change the value from the client, it will not replicate, you need to get a server script to do it, if the client could do it it would be usually exploitable

--On a server script
local remoteEvent=Instance.new("RemoteEvent")--Get the adress of your remote event here, it allows communication between server and client

local function decideWinner()
	local northTeamPoints=0
	local southTeamPoints=0
	local Winner
	
	for _,player in pairs(game.Players:GetPlayers()) do
		if player.Team==game.Teams.North then
			northTeamPoints += player.leaderstats.Value.Value
		elseif player.Team==game.Teams.South then
			southTeamPoints +=player.leaderstats.Value.Value
		end
	end
	
	if northTeamPoints>southTeamPoints then
		remoteEvent:FireAllClients(game.Teams.North)
	elseif southTeamPoints>northTeamPoints then
		remoteEvent:FireAllClients(game.Teams.South)
	elseif southTeamPoints==northTeamPoints then
		remoteEvent:FireAllClients(nil)
	end
	
end

--When you go to decide the winner
decideWinner()

--On a local script

remoteEvent.OnClientEvent:Connect(function(winner:Team)
	local message
	if not winner then--Tied
		message="It's a tie!"
	end
	
	message="The winner is"..winner.Name.."!"
	
	plr.PlayerGui.TopText.Time.Text=message
end)

It’s hard to really know what the right answer is since i don’t know much of how anything is set up

4 Likes

how to i refer to the remote event with the local script because the remote event has no parent

4 Likes

I made the remote event in the script because yes, create one before running the game on ReplicatedStorage, and then reference it from both scripts

4 Likes

its not working again,.,.,.,.,.,.,.,.,.,., :thinking:

4 Likes

wait does my game need to be published for it to work

3 Likes

Remote events don’t need for the game to be published to work, are you sure you’re firing the function in the correct time and remember that it has to be a server script in ServerScriptService

3 Likes