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

Script replicating model multible times? [Solved]

Asked by 6 years ago
Edited 6 years ago

This replicates the 2nd leg 14 times. The 1st leg is duplicated 3 times but the chest is only duplicated once? I am confused of why it is doing this. It is gui activated so that might have something to do with it but I added a denounce and still the same happens. This causes lag with big models since it can duplicate many times over. Any idea? - thx

        local g = game.ReplicatedStorage.Models.bTrex.Leg2:clone()
        g.Parent = Me
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me["Right Leg"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
         h[i].CanCollide = false

edit: added this to top

    if Me:findFirstChild("Humanoid") ~= nil and Me:findFirstChild("Chest") == nil then

1 answer

Log in to vote
0
Answered by 6 years ago

You had it for i=1, #C do so it will do it a lot of times its like while wait do try adding a Trigger when you want to do it make a button

script.Parent.MouseButton1Click:connect(function()
end)

Here this will do the script every 10 seonds

local g = game.ReplicatedStorage.Models.bTrex.Leg2:clone()
    g.Parent = Me
    local C = g:GetChildren()
    while wait(10) do              --Trigger
        if C[i].className == "Part" then
            local W = Instance.new("Weld")
            W.Part0 = g.Middle
            W.Part1 = C[i]
            local CJ = CFrame.new(g.Middle.Position)
            local C0 = g.Middle.CFrame:inverse()*CJ
            local C1 = C[i].CFrame:inverse()*CJ
            W.C0 = C0
            W.C1 = C1
            W.Parent = g.Middle
        end
            local Y = Instance.new("Weld")
            Y.Part0 = Me["Right Leg"]
            Y.Part1 = g.Middle
            Y.C0 = CFrame.new(0, 0, 0)
            Y.Parent = Y.Part0
    end end

    local h = g:GetChildren()
    for i = 1, # h do
        h[i].Anchored = false
     h[i].CanCollide = false

This will only do it when a gui is clicked

local g = game.ReplicatedStorage.Models.bTrex.Leg2:clone()
    g.Parent = Me
    local C = g:GetChildren()
    script.Parent.MouseButton1Click:connect(function()         --Trigger
        if C[i].className == "Part" then
            local W = Instance.new("Weld")
            W.Part0 = g.Middle
            W.Part1 = C[i]
            local CJ = CFrame.new(g.Middle.Position)
            local C0 = g.Middle.CFrame:inverse()*CJ
            local C1 = C[i].CFrame:inverse()*CJ
            W.C0 = C0
            W.C1 = C1
            W.Parent = g.Middle
        end
            local Y = Instance.new("Weld")
            Y.Part0 = Me["Right Leg"]
            Y.Part1 = g.Middle
            Y.C0 = CFrame.new(0, 0, 0)
            Y.Parent = Y.Part0
    end end)

    local h = g:GetChildren()
    for i = 1, # h do
        h[i].Anchored = false
     h[i].CanCollide = false

Hope this works

Ad

Answer this question