Control Point Capture Point Script

  1. What do you want to achieve?
    I’m making a team control point system

  2. What is the issue?
    I can’t add a wait as the script runs every frame so it doesn’t wait for the cooldown in adding to controlpoints

  3. What solutions have you tried so far?
    I’ve tried using task.spawn, after I had an issue where if the player left early the script would fire player left and player entered constantly, but that still didn’t wait between adding to the controlpoints

server

local zone = workspace.Zone
local players = game:GetService("Players")
local runservice = game:GetService("RunService")

local overlap = OverlapParams.new()
overlap.FilterDescendantsInstances = {zone, workspace.Baseplate}

overlap.FilterType = Enum.RaycastFilterType.Exclude

local playerlist = {}
local playercount = 0
local teamcount = 0
local zoneteams = {}

runservice.Heartbeat:Connect(function()
	
	local zonearea = workspace:GetPartBoundsInRadius(zone.Position, 20, overlap)
	local zonelist = {}
	
	for i,v in zonearea do
		
		local player = players:GetPlayerFromCharacter(v.Parent)
		
		if player then
			if not playerlist[player] then
				playerlist[player] = player
				if not zoneteams[player.Team.Name] then
					zoneteams[player.Team.Name] = 1
					teamcount += 1
				else
					zoneteams[player.Team.Name] += 1
				end
				print("player enter")
			end
		end
		
		zonelist[player] = player
		
		if teamcount == 1 then
			
			if zone:GetAttribute("ControlTeam") == player.Team.Name then continue end
			
			if zone:GetAttribute("ControlPoint") >= 100 then
				
				if zone:GetAttribute("ControlTeam") == "Neutral" then
					zone:SetAttribute("ControlTeam", player.Team.Name)
				else
					zone:SetAttribute("ControlTeam", "Neutral")
					zone:SetAttribute("ControlPoint", 0)
				end
			end
			
			--task.wait(1) doesn't wait
			zone:SetAttribute("ControlPoint", zone:GetAttribute("ControlPoint") + 1)
		end
	end
	
	for i,v in playerlist do
		if not zonelist[v] then
			playerlist[v] = nil
			if zoneteams[v.Team.Name] == 1 then
				zoneteams[v.Team.Name] = nil
				teamcount -= 1
			else
				zoneteams[v.Team.Name] -= 1
			end
			print("player left")
		end
	end
end)