I have a module (a gamemode) which loops through a timer looking for specific control points. However my problem is that since I have numerous control points, they all end up sharing the same variables.
So below basically finds the closest point to a player. And then I have code latter down which handles the capturing of said point. However, if I have 2 players capturing 2 seperate points it doesn’t work as intended. How can I get this module to function seperately for each individual control point, instead of looping through everyone
while true do
local Capturer
local Capturers = 0
local Defenders = 0
local ClosestPoint
for _, player in pairs(Players:GetPlayers()) do
local Character = player.Character
if Character then
local HumanoidRootPart = Character.PrimaryPart
if HumanoidRootPart then
local Humanoid = Character:FindFirstChildWhichIsA('Humanoid')
for _, v in pairs(ControlPoints:GetChildren()) do
if player:DistanceFromCharacter(v.PrimaryPart.Position) <= Range then
if Humanoid.Health > 0 then
ClosestPoint = v
end
end
end
end
end
end
wait()
end