CanCollide (true/false) Messing with transparency on/off script

So i’m trying to make my script make a few parts in a folder’s transparency set to 0 and CanCollide set to true when the player touches a certain part however when I include the CanCollide value in my code it just breaks it (no errors) and when I run the code in the playtest it also deletes all the parts in the workspace for some reason.

--scripted by sandy7512
local startTime = os.time()

local mainGame = game.Workspace:WaitForChild("scriptedparts")
local purchasePart = mainGame:WaitForChild("purchaseParts"):FindFirstChildWhichIsA("BasePart")
local partsChanged = mainGame:WaitForChild("partsChanged")
local partIsTouched = false

for _, v in partsChanged:GetChildren() do
    if v:IsA("BasePart") then
        v.BrickColor = BrickColor.new("Bright red")
        v.Transparency = 1
    end
end

local function checkChanged()
    for _, v in partsChanged:GetChildren() do
        if v:IsA("BasePart") then
            v.BrickColor = BrickColor.new("Bright blue")
            v.Transparency = 0
        end
    end
end


local partIsTouched = false
local function touchFunc(otherPart)
    if not partIsTouched then
        partIsTouched = true
        if otherPart.Parent:FindFirstChild("Humanoid") then
            checkChanged()
        end
        task.wait(2)
        partIsTouched = false
    end
end

--This is the code with ne debounce check
--[[local function touchFunc(otherPart)
     if otherPart.Parent:FindFirstChild("Humanoid") then
         print(otherPart.Name, "touched")
        checkChanged()
    end
    task.wait(2)
    partIsTouched = false
end
]]

purchasePart.Touched:Connect(touchFunc)

--load time check
print("PurchasePartServer loaded in", os.time() - startTime, "seconds")

In the code above I didn’t the “v.CanCollide = false/true” in the loops that iterate thru my folders but I appreciate any help!

Your parts are probably not Anchored and when you make them CanCollide = false they fall out of the world (hit the destroy plane set by Workspace.FallenPartsDestroyHeight) There’s nothing else in this code that would be able to delete parts.

Yup, that was the problem, can’t believe I missed that.