I set up code to make a wall made up of parts that would unanchor when I chat the word break, but when I say return it makes a copy of the wall and deletes the old wall, but the script no longer works for the new wall
local wall = script.Parent
local clone = wall:Clone()
local bricks = wall.Bricks:GetChildren()
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if player.Name == "DedNation" then
if string.lower(msg) == "break" then
for _, brick in pairs(bricks) do
brick.Anchored = false
end
elseif string.lower(msg) == "return" then -- Checks if the msg is return
wall:Destroy() -- Destroys the wall
clone.Parent = game.Workspace
end
end
end)
end)
How can I rewrite this code so that I can break and return it an infinite amount of times?
