this code seems perfectly fine, yet when i touch the blue flag, i get like 500 captures spammed without returning to the red flag
local flagB = game.Workspace.flags.flagBlue
local hitboxR = flagR:FindFirstChild("flagHitbox")
local hitboxB = flagB:FindFirstChild("flagHitbox")
local flagHolderR = nil
local flagHolderB = nil
local flagStandPosR = game.Workspace.redSide.flagStandRed.Position
local flagStandPosB = game.Workspace.blueSide.flagStandBlue.Position
local flagRPos = flagR.PrimaryPart.Position
local flagBPos = flagB.PrimaryPart.Position
local redCaptures = 0
local blueCaptures = 0
hitboxB.Touched:connect(function(hit) -- BLUE
local h = hit.Parent:FindFirstChild("Humanoid")
if not h then return end
local c = h.Parent
local p = game.Players:GetPlayerFromCharacter(c)
if not p then return end
if p.Team == game.Teams.red then
print(p.Team)
flagHolderB = p
print(flagHolderR)
print(flagHolderB)
print(p)
end
if flagHolderR == nil then return end
if p.Team == game.Teams.blue and flagHolderR == p then
flagHolderR = nil
blueCaptures = blueCaptures + 1
returnFlag(flagR)
print("blue capture", blueCaptures)
end
end)
hitboxR.Touched:connect(function(hit) -- RED
local h = hit.Parent:FindFirstChild("Humanoid")
if not h then return end
local c = h.Parent
local p = game.Players:GetPlayerFromCharacter(c)
if not p then return end
if p.Team == game.Teams.blue then
flagHolderR = p
end
if flagHolderB == nil then return end
if p.Team == game.Teams.red and flagHolderB == p then
flagHolderB = nil
redCaptures = redCaptures + 1
returnFlag(flagB)
print("red capture", redCaptures)
end
end)
function returnFlag(flag)
if flag == flagR then
flagRPos = flagStandPosR
else
flagBPos = flagStandPosB
end
end```
** You are now Level 3! **