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 4 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:

01local CollectionService = game:GetService("CollectionService")
02local woodwalls = CollectionService:GetTagged("WoodWall")
03 
04for _, TaggedPart in pairs(woodwalls) do
05    local model = TaggedPart
06    local enabled = true
07    local clone = model:Clone()
08 
09    TaggedPart.Touched:Connect(function(hit)
10        if enabled == true and hit.Parent:FindFirstChild("Humanoid") then
11            enabled = false
12            model:Destroy()
13            wait(20)
14            local lclone = clone:Clone()
15            lclone.Parent = game.Workspace
16            model = lclone
17            enabled = true
18        end
19    end)
20end

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 — 4y
0
So like make it invisible and then make it visible again? Bob4koolest 78 — 4y
0
That worked great thanks :) Bob4koolest 78 — 4y

Answer this question