Hello! I’m creating a payload game similar to TF2.
However, even though it does count the number of players in the region, it doesn’t work if I use an if statement to check for the player’s team. I’m genuinely stumped. Help please!
--Objects
local Cap = script.Parent.CaptureArea
local Model = script.Parent.InvisibleWall
--Services
local players = game:GetService("Players")
local Team = game:GetService("Teams")
function DefendingTeam()
local min = Cap.Position - (0.5 * Cap.Size)
local max = Cap.Position + (0.5 * Cap.Size)
local region = Region3.new(min,max)
local t = {}
local parts = workspace:FindPartsInRegion3(region)
for _, v in pairs(parts) do
local plr = players:GetPlayerFromCharacter(v.Parent)
if plr and not table.find(t, plr) then
if plr.Team.Name == "Defenders" then
table.insert(t, plr)
end
end
end
return t
end
function AttackingTeam()
local min = Cap.Position - (0.5 * Cap.Size)
local max = Cap.Position + (0.5 * Cap.Size)
local region = Region3.new(min,max)
local t = {}
local parts = workspace:FindPartsInRegion3(region)
for _, v in pairs(parts) do
local plr = players:GetPlayerFromCharacter(v.Parent)
if plr and not table.find(t, plr) then
--print("This works")
--print(plr)
if plr.Team.Name == "Defenders" then
table.insert(t, plr)
end
end
end
return t
end
while wait(0.1) do
DefendingTeam()
AttackingTeam()
print("Defenders: ", #DefendingTeam())
end