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

How do I respawn a model of a wall with the script working for each new copy?

Asked by 2 years ago

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?

1 answer

Log in to vote
0
Answered by 2 years ago

you need to turn it into a server script, because the script is a child of the wall, the wall destroys and so does the script. so you need to do all this in a server script (copy and paste it into a script in server script service) and make a variable of the script, i recommend storing it in server storage. variable of the script, clone it, set it's parent to the new wall.

Ad

Answer this question