So i made a capture the flag script that increases your score when you are close enough to the flag, but it doesnt work with multiple teams
it doesnt print anything and no errors
my script:
local GermanyScore = 0
local AmericaScore = 0
local range = 20
local flag = script.Parent
local Teams = game:GetService("Teams")
local players = game:GetService("Players")
local function FindPlayerNearFlag()
local PlayerTable = players:GetPlayers()
for _,v in pairs (PlayerTable) do
local Character = v.Character
if not Character then return end
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Distance = (HRP.CFrame.p - flag.CFrame.p).Magnitude
if Distance < range and Humanoid.Health > 0 and v.Team == Teams["Germany"] then
GermanyScore = GermanyScore + 1
else if Distance < range and Humanoid.Health > 0 and v.Team == Teams["America"] then
AmericaScore = AmericaScore + 1
end
end
end
while true do
FindPlayerNearFlag()
print(GermanyScore.." Germany")
print(AmericaScore.." America")
wait(1)
end
end