How to add leaderstats together?

local function possessionAlgorithm (time1,time2) --Here time 1 and 2 is the amount of time both teams had the ball
	local total = time1+time2
	local team1Possession = (time1/total) * 100
	local team2Possession = (time2/total) * 100
	local possessionStats = {
		["Green"] = team1Possession,
		["Red"] = team2Possession
	}
	return possessionStats
end

How would I be able to get Green Team player value and the other player value and add them together any help is appreciated

2 Likes

do you want to retrieve the stats from within or outside the function?

1 Like

idm which way just want the value of leaderstats of player on Green and Red team

1 Like

unless i misinterpretted the entire thing… uh oh…

1 Like

so do you have designated teams in the Team service?

1 Like

What do you mean by ‘other value’?

1 Like

I have like TimeOnBall value whcih is saved in player i just don’t know how to get the value of that and assign it to time1 and time 2

1 Like

Example that might help:

local Teams = game:GetService('Teams');
local Amount = 0

for _, Player in ipairs(Teams.Red:GetPlayers()) do
    Amount = Amount + Player.leaderstats.Points.Value
end

Glad it worked! :happy3: