Help on Raid / Flag Capture System

Hi there,
I’m currently working on a raid system where a team of players can go to a flag point to capture it. However, they must hold off that position until the capture bar is full. I’ve tried using touch and touchEnded in my scripts so that players must stay in that position to increase the capture bar size 'till it’s full, but it’s whack and doesn’t work out like I intend it to be. What may be the best approach to this?
Huge Thanks in Advance!

1 Like

You can probably use Region3 to detect whether the player is near the flag or not

2 Likes

You can use @DatabaseReplace’s method of using a Region3 to see if you should increase the capture bar size or if you want you can try a magnitude approach. The magnitude approach allows you have a spherical range for your flag capture area. Your code would be similar to this

-- some kind of loop out here 
for _, player in pairs (Players:GetPlayers()) do
    local distance = (player.Character.HumanoidRootPart.Position - flagBase.Position).magnitude
    if distance < MAX_RADIUS_SIZE then
        -- you may want to add a check here to see if same team to avoid
        -- capture points accruing just based in the number of players nearby
        flagCapturePoints = flagCapturePoints + 1
    end
end
1 Like

im not sure you need(that code below),because he wants the player on the point,also MAX_RADIUS_SIZE is a variable,which has no need since your using magnitude

if distance < MAX_RADIUS_SIZE then
1 Like

You can also use GetTouchingParts on an invisible part around the flag in a loop

1 Like

Honestly, I would go with the magnitude method listed above. You could use Region3 but I’m fairly certain that the magnitude method is easier and is better for multiple flag points because you can loop through all of the flag points and check each player’s position.

If they are within range then create a while loop where it decreases the flag value as long as the player is less than X studs from the flag.

2 Likes

I’m not quite sure what you’re saying. Even if he had the magnitude, without a check against some variable, which in this case it’s MAX_RADIUS_SIZE, it would increase the counter despite the user being over 1K studs away from the flag which is not what OP is asking.

2 Likes

wym,the magnitude is the eastiest way,and will get the job done,as they will have to be in the point position,unless its like a part,which i doubt

1 Like

okay,i now agreee,because your trying to double check

1 Like

You’re not understanding me. You need this check. Think of it as a sphere where the center of the sphere is the center of the flag. OP wants everyone within a range of the flag to increase the counter. If you do not add the check, there is no set range meaning anyone anywhere in the game would increase the ticker. With the range, it limits the scope to the players that are nearby the flag pole.

1 Like