Good morning guys, so i am coding a capture the flag/ control point system which is gonna to be implemented in my game, but i have ran to a problem and its making my brain a salad, which is how can i detect how many players of a certain team is in the capture radius and how many of the other are in the radius? here is my progress for the moment:
local capturePoints = game.ReplicatedStorage.CaptureProgress
local FlagPartRadius = game.Workspace.Part
local maxRadiusofCapture = 40
local capturedEvent = game.ReplicatedStorage:WaitForChild("CapturedEvent")
local sendDATA = game.ReplicatedStorage:WaitForChild("SendData")
local capturingFlag = game.ReplicatedStorage:WaitForChild("CapturingFlag")
local capturing = false
local capturers = 0
local defenders = 0
local TeamFlag
while wait(0.5) do
for i, playersInTheCircle in pairs(game.Players:GetPlayers()) do
local char = playersInTheCircle.Character or playersInTheCircle.CharacterAdded:Wait()
local distance = (char.HumanoidRootPart.Position - FlagPartRadius.Position).Magnitude
if distance < 40 then
--Chequeamos si la bandera ya esta tomada o no lo esta.
if TeamFlag == nil then
--Hacemos que el equipo en el que este dicha persona ahora sea el TeamFlag
TeamFlag = playersInTheCircle.Team.Name
print(TeamFlag)
capturedEvent:FireAllClients(TeamFlag)
end
if playersInTheCircle.Team ~= TeamFlag then
capturers += 1
capturer = playersInTheCircle
capturingFlag:FireClient(capturePoints)
sendDATA.OnServerEvent:Connect(function()
TeamFlag = playersInTheCircle.Team
end)
end
end
end
end
Thanks in advance!!! Hope you have a great day!