Constantly Search for parts with Tag

I have this script that gets the parts with the tag “Bird” and then makes them rotate and add 1 to a value if they are destroyed, but whenever I try to move a part with the tag from ReplicatedStorage to the Workspace, the script doesn’t affect it.

Is there a way to make the script constantly look for parts with tag and if it finds one, then it applies the same effects as the other ones?

local CS = game:GetService("CollectionService")

local value = game.Workspace.Value

local RunService = game:GetService("RunService")
local ROTATE_SPEED = 100

local sound = workspace.Coin

local backup = game.ReplicatedStorage.Turko:Clone()



for _, part in CS:GetTagged("Bird") do
	part.CanCollide = false
	local function onTouched(other)
		local character = other.Parent
		local humanoid = character:FindFirstChildWhichIsA("Humanoid")

		if humanoid then
			part:Destroy()
			
		end
	end

	part.Touched:Connect(onTouched)
	
	
	RunService.Heartbeat:Connect(function(step)
		local rotationAmount = math.rad(ROTATE_SPEED * step)
		part.CFrame = part.CFrame * CFrame.Angles(0, rotationAmount, 0)
	end)
	
	
	local function onPartDestroyed()
		value.Value = value.Value + 1
		sound:Play()
		
	end

	part.AncestryChanged:Connect(function()
		if not part:IsDescendantOf(game) then
			onPartDestroyed()
		end
	end)
	
	
end

Hi there,

You absolutely can with CollectionService.GetInstanceAddedSignal. The link provided has sample code that matches your scenario.

2 Likes

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