Why has collection service stopped working?

I made a script whereas when this turtle is touched, the player gets damaged and an explosion happens, but even though i tagged it and made the collection service script for it, it doesnt work, the script was working before but suddenly it just stopped working, anyone know why?

local CS = game:GetService("CollectionService")
--normal basic obstacles
CS:GetInstanceAddedSignal("Obstacle"):Connect(function()
	for i, model in pairs(CS:GetTagged("Obstacle")) do
		local db = false
		model.Touched:Connect(function(hit)
			print("Damaged")
			if hit.Parent:FindFirstChild("Humanoid") then
				local db = false
				if db == false then 
					
				hit.Parent.Humanoid.Health -= 30
				local Bomb = Instance.new("Explosion")
				Bomb.BlastPressure = 100000
				Bomb.BlastRadius = 10
				Bomb.Position = model.Position
				Bomb.Parent = model
			db = true
			wait(4)
			db = false
			end
			end
		end)
	end
end)

The tagged objects are being loaded in before the code, so it doesn’t register these objects. You should run the code for all current objects and whenever a new object is added.

local function obstacleAdded(model)
    -- do something
end

CollectionService:GetInstanceAddedSignal("Obstacle"):Connect(obstacleAdded)
for i, model in pairs(CollectionService:GetTagged("Obstacle")) do
    task.spawn(obstacleAdded, model)
end
1 Like