So I'm currently editing a flag capture system and I want to award a player with points while he is capturing the flag, but when an opposing team comes in range the point awarding should stop - currently it doesn't, it awards both players with points when they're in range of the flag.
So how would I check for opposing team member approaching the flag and then stop the point awarding?
I currently use this:
players = {}
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(players, v)
end
game.Players.PlayerAdded:connect(function(p) table.insert(players, p) end)
bin = script.Parent.Base
neutral = script.Parent.NeutralColor.Value
distance = script.Parent.CaptureDistance.Value
while true do
wait()
for i,v in pairs(players) do
if v.Character ~= nil then
torso = v.Character:findFirstChild("Torso")
if torso ~= nil then
if v.Character.Humanoid.Health > 0 then
if (torso.Position-bin.Position).magnitude <= distance then
if v.TeamColor ~= neutral then
if v.TeamColor ~= script.Parent.CurrentOwner.Value then
wait(2)
if (torso.Position-bin.Position).magnitude <= distance then
v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 5
end
end
end
end
end
end
end
end
end

3 comments
you can just do local players = game.Players:GetPlayers(), although I recommend updating the table by removing players that left with the PlayerRemoving event
also, why use if (torso.Position-bin.Position).magnitude <= distance twice?
Just so the player isn't awarded the points if he leaves the area within the 2 second wait()