I am creating system, where raiders need to capture 3 terms (A, B, C) while defender must defend them. Each term is unlocked after previous one (B is unlocked after capturing A and C after capturing B). Each term takes x second to capture. While raiders are in control of a term, countdown is getting higher until x second reaches, and while defenders are in control of a term, countdown is getting lower until 0.
Depending on the game, the most basic solution is to make a 3 Part. Each named respectively as “A”, “B” and “C”.
Under these parts, create a Boolean value, Number Value and Name / Object Value.
You can use .Touched event, it might be inconsistent, but it get the job done.
First, check if “A” can be captured before other can. Then, using .Touched event, check who is touching and the team of player.
If it exist, increase the Number value. Using .Changed event, check the statement. For example,
if NumberValue.Value == 100 then
-- Procedure can be run here
end
If NumberValue.Value == 100 then, NameValue.Value can be set to player who has captured the point and set the BooleanValue.Value to false to block any person from previous team to capture it again.
While the Part.NameValue.Value ~= nil then, reduce / increase the timer respectively.
local PointA = game.Workspace.A
local Raiders = game.Teams.Raiders
local Defenders = game.Teams.Defenders
local capturedBy = nil
PointA.Touched:Connect(function(part)
if PointA.Captureable.Value == true then
local player = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
if player and player.TeamColor == Raiders.TeamColor and (capturedBy == nil or capturedBy == "Def") then
capturedBy = "Raid"
while PointA.Captureable.Value == true and PointA.Value.Value < 100 do
PointA.Value.Value += 1
wait(1)
end
PointA.Captureable.Value = false
elseif player and player.TeamColor == Defenders.TeamColor and capturedBy == "Raid" then
capturedBy = "Def"
while PointA.Captureable.Value == true and (PointA.Value.Value < 100 and PointA.Value.Value > 0) do
PointA.Value.Value -= 1
wait(1)
end
end
end
end)