Need help with collection service

for _,v in CS:GetTagged("CrystalSpawner") do
    local Crystal = v:FindFirstChild("Crystal")
    spawnCrystal(Crystal)
    
    --local debounce = false
    Crystal.Touched:Connect(function(part)
        print("a")
        local score = 1

        if part.Parent:FindFirstChild("Humanoid") then -- and not debounce then
            --debounce = true
            Crystal.Transparency = 1
            local plr = game.Players:GetPlayerFromCharacter(part.Parent)
            if Crystal.BrickColor == BrickColor.new("Pink") then
                score = 1
            elseif Crystal.BrickColor == BrickColor.new("Electric blue") then
                score = 2
            elseif Crystal.BrickColor == BrickColor.new("Sea green") then
                score = 3
            end
            plr:WaitForChild("ScoreFile").backpackValue.Value = plr.ScoreFile.backpackValue.Value + score
            --wait()
            --debounce = false
        end
        
        wait(crystalModule.CrystalSpawnCooldown)
        Crystal.Transparency = 0
        spawnCrystal(Crystal)
    end)
end

When i touch the part, everything inside the function didn’t get activate, how should i fix it?

We might need to see your crystal spawner in the explorer. What does the function spawnCrystal do?

it just make a part visible, nothing special

Are you sure the for loop runs (are objects tagged with “CrystalSpawner”)? Add a print statement there too.

Post the spawnCrystal code anyways, if it’s looping then your connection will never be made.

yes its looping through the objects

local function RandomFromWeightedTable(OrderedTable)
	local TotalWeight = 0

	for Piece, Weight in pairs(OrderedTable) do
		TotalWeight += Weight
	end
	local Chance = Random.new():NextInteger(1, TotalWeight)

	local Counter = 0

	for Piece, Weight in pairs(OrderedTable) do
		Counter += Weight

		if Chance <= Counter then
			return Piece
		end
	end
end

local function spawnCrystal(a)
	local color = RandomFromWeightedTable(crystalModule.CrystalChance)

	if color == "normal" then
		a.BrickColor = BrickColor.new("Pink")
	elseif color == "double" then
		a.BrickColor = BrickColor.new("Electric blue")
	else
		a.BrickColor = BrickColor.new("Sea green")			
	end
end

oh also, the part with the tag was originally in replicated storage, but later transported into the workspace