Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clones are not affected by script of initial object?

Asked by 3 years ago

I'm making a wall where if the player touches a part of it, it deletes that section and regenerates later on by creating a clone of it, and the initial wall works as expected. The problem is, the clones don't seem to be affected by the deleting code (they regenerate but don't get deleted when the player touches them). I've tagged all parts of the wall together since they essentially have the same behavior. Here's the script:

local CollectionService = game:GetService("CollectionService")
local woodwalls = CollectionService:GetTagged("WoodWall")

for _, TaggedPart in pairs(woodwalls) do
    local model = TaggedPart
    local enabled = true
    local clone = model:Clone()

    TaggedPart.Touched:Connect(function(hit)
        if enabled == true and hit.Parent:FindFirstChild("Humanoid") then
            enabled = false
            model:Destroy()
            wait(20)
            local lclone = clone:Clone()
            lclone.Parent = game.Workspace
            model = lclone
            enabled = true
        end
    end)
end

I would really appreciate any help (preferably in the form of a code snippet rather than just general advice or links).

0
you should do model.Transparency = 1 stevenfury91 -17 — 3y
0
So like make it invisible and then make it visible again? Bob4koolest 78 — 3y
0
That worked great thanks :) Bob4koolest 78 — 3y

Answer this question