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)