# Need Someone To Help Me With Math In Script

Hi, I’ve been making a script for capturing a point. There would be four teams and whoever has the most players is capturing, resets when no team is on the point. This is the math I used for calculating the team with the most players and for the script but It is not working and iv been frustrated for a few days on it and finaly decided to post on devforums. If you have any idea how to make this work then let me know.

``````local part = game.Workspace.PointCapture
local team1 = 0
local team2 = 0
local team3 = 0
local team4 = 0
local goingon = false
local capturevalue = game.Workspace.Capture
local mostvalueteam = 0
local savedplayernames = {}
local beingtouched = false
while wait(1) do
local pointsave = game.Workspace.CapturePlayers
for i,v in pairs(pointsave:GetChildren()) do
if v.Value == "team1" then
team1 = team1 + 1

end
if v.Value == "team2" then
team2 = team2 + 1

end

if v.Value == "team3" then
team3 = team3 + 1

end

if v.Value == "team4" then
team4 = team4 + 1

end

end

local list = {team1,team2,team3,team4}

for index, val in pairs(list) do --> going through the list
if index and val > 0 then
mostvalueteam = index
if list[index + 1] and list[index + 1] == list[index] then
mostvalueteam = 0
capturevalue.Value = 0
else
mostvalueteam = index
end
if list[index + 1] and list[index + 1] > val then --> checking if the next value is the same as [str]
mostvalueteam = index + 1
else
mostvalueteam = index
end
else
mostvalueteam = 0
capturevalue.Value = 0
end
end
print(list)
game.Workspace.pointhitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
beingtouched = true
end

end)
game.Workspace.pointhitbox.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
beingtouched = false
end

end)

if mostvalueteam == 0 or beingtouched == false then
goingon = false
elseif mostvalueteam > 0 and beingtouched == true then
goingon = true
end
print(goingon,mostvalueteam,beingtouched)
if goingon == true then
if capturevalue.Value < 100 then
capturevalue.Value = capturevalue.Value + 1
end
if capturevalue.Value == 100 then
local Players = game:GetService("Players")

for i,v in pairs(Players:GetChildren()) do
local Team = "team"..mostvalueteam
v.PlayerGui.Capturepoint.TextLabel.Text = "Point Captured By "..Team
if v.Team == Team then
local char = v.Character
char.Humanoid.MaxHealth = 150
char.Humanoid.Health = 150
char.Humanoid.WalkSpeed = 30
end
end
end
end
end
````````
1 Like

I don’t think it has anything to do with the math of the script, but rather the hierarchal order of the functions within this:

For example this function is being connected every 1 second, when it should be outside of the while true do entirely:

Tested, That is not a problem.It has to do with the math, the most value team variable is giving an incorrect value when players enter the point.

What number is mostvalueteam printed as when a player enters?

Hey! I would like you give you a helping hand. Before that, could you specify the current issue of the code? What is the expected result and the actual result (issue) of the code?

when two people are on the point, it should stop capturing and when one team has most player it captures and if all the team aint there then it resets back to 0

if there are two players on the point then it doesnt go back to most value team = 0 , it just keeps going