Part doesn't destroy in time

Hello there,
I making a CTF game and the flag isn’t destroying in time when you touch base, so it bugs out and gives your team almost 5 extra points.

If anyone can tell me what is happening, I would really apprecaite.
Here’s the script:

local flag = script.Parent

flag.Touched:Connect(function(hit)
	local hitParent = hit.Parent
	local h = hitParent:FindFirstChild("Humanoid")
	
	if h then
		local plr = game.Players:WaitForChild(hitParent.Name)
		
		if plr.Team.TeamColor ~= flag.BrickColor then
			flag.Transparency = 1
			flag.CanCollide = false

			local char = h.Parent
			local attachPart = char:WaitForChild("HumanoidRootPart")

			local newPart = Instance.new("Part")
			newPart.Name = "BlueFlag"

			--Unspecial
			newPart.Parent = char
			newPart.Size = flag.Size
			newPart.Anchored = false
			newPart.CanCollide = false

			--special
			newPart.Material = Enum.Material.Neon
			newPart.BrickColor = flag.BrickColor

			--weld
			local weld = Instance.new("Weld")
			weld.Parent = attachPart
			weld.Part0 = attachPart
			weld.Part1 = newPart

			--rotate
			weld.C0 *= CFrame.Angles(math.rad(0), math.rad(90), math.rad(90)) * CFrame.new(1, 1, 0)
		elseif plr.Team.TeamColor == flag.BrickColor then
			local f = hitParent:FindFirstChild("RedFlag")
			if f then
				f:Destroy()
				print("Score!")
			end
		end
	end
end)

Thank you for any help.

Add a debounce to your function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.