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
``