Maybe I’m over looking something, but this while loop iterates over all players in the game every 0.2 seconds and compares their distance, yet it only registers the most recent player to join the game?
Eg:
Player 1 joins the game, he’s registered by the system.
Player 2 joins, player 1 is no longer registered and only player 2 is registered.
Apologies for messy code.
while wait(0.2) do
if (capturePart.Position - bGoal.Position).magnitude <= 0.5 then
TugOfWar:End("RED")
break
elseif (capturePart.Position - rGoal.Position).magnitude <= 0.5 then
TugOfWar:End("BLUE")
break
end
for _, PlayerValue in pairs (game.Players:GetPlayers()) do
if PlayerValue
and PlayerValue.Character
and PlayerValue.Character:FindFirstChild("HumanoidRootPart")
and (PlayerValue.Character.HumanoidRootPart.Position - capturePart.Position).Magnitude < 8 then
if PlayerValue.Team == redTeam then
if lastOwner == blueTeam or lastOwner == nil then
print("lastowner == blueteam or lastOwner == nil AND player is == red team")
lastTween = TweenService:Create(capturePart, TInfo, {CFrame = bGoal.CFrame})
lastTween:Play()
lastOwner = redTeam
elseif lastTween ~= nil and lastOwner == redTeam then
print("lasttween ~= nil and lastOwner == redTeam")
lastTween:Play()
end
elseif PlayerValue.Team == blueTeam then
if lastOwner == redTeam or lastOwner == nil then
print("lastowner == blueteam or lastOwner == nil")
lastTween = TweenService:Create(capturePart, TInfo, {CFrame = rGoal.CFrame})
lastTween:Play()
lastOwner = blueTeam
elseif lastTween ~= nil and lastOwner == blueTeam then
print("lasttween ~= nil and lastOwner == blueteam")
lastTween:Play()
end
end
else
if lastTween ~= nil then
lastTween:Pause()
end
end
end -- end of for loop
end
end