How would I check if something is consistently touching something?

I know Touched fires if a part is touched, but how would you keep it firing while a player is not moving but still touching the part? I’m trying to make a flag capture system where if a player is touching the base of the flag it will move the flag down if the team doesn’t own the flag, and vise versa. However, the player for the moment has to keep moving so they keep touching the base part.

Code:


local Players = game:GetService("Players")
local britishHeld = true
local flag = script.Parent.Flag
local flagholder = script.Parent
local base = flagholder.Flagpole.Base
local cooldown = false
local timesTouched = 0

base.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
		local plr = Players:GetPlayerFromCharacter(hit.Parent)
		if plr.Team.TeamColor == BrickColor.new("Bright green") and britishHeld == true then
			if timesTouched < 23 then
				if not cooldown then
					cooldown = true
					timesTouched += 1
					for i, v in pairs(flag:GetChildren()) do
						v.CFrame = v.CFrame + Vector3.new(0,-1,0)
					end
					print(timesTouched)
					wait(1)
					cooldown = false
				end
			end
		elseif plr.Team.TeamColor == BrickColor.new("Bright red") and britishHeld == true then
			if timesTouched ~= 0 then
				if not cooldown then
					cooldown = true
					timesTouched -= 1
					for i, v in pairs(flag:GetChildren()) do
						v.CFrame = v.CFrame + Vector3.new(0,1,0)
					end
					print(timesTouched)
					wait(1)
					cooldown = false
				end
			end
		end
	end
end)

I think you have to use Region3. I watched some vids on it and it seems to be right. If I’m not, please correct me.

Alright, I’ll go check that out and see how it goes.

1 Like

I suggest using Zone+

It’s pretty easy to use

1 Like

You can use the TouchEnded event.

I don’t think TouchEnded would work for this (the parts have to be moving). I would also recommend Zone+.