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

How would I go about adding welding to this script?

Asked by 3 years ago

I have made a building system and I want parts to get destroyed and have it fall down and the current script all works I just want to have the parts weld together when they are placed. Here is the script

local rf = game.ReplicatedStorage.MouseTarget
Build = game.ReplicatedStorage.Build

rf.OnServerEvent:Connect(function(Player, MouseTarget, TargetSurface)
    if MouseTarget.Parent.Parent.Owner.Value == Player.Name then
        local B = Build:Clone()
        B.Parent = MouseTarget.Parent.Parent.Blocks
        if workspace.CanBuild.Value == true then
            if MouseTarget.Parent.Parent.Name == "Plot1" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot2" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot3" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -113 or MouseTarget.Parent.Parent.Name == "Plot4" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -118 or MouseTarget.Parent.Parent.Name == "Plot5" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -113 or MouseTarget.Parent.Parent.Name == "Plot6" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot7" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 or MouseTarget.Parent.Parent.Name == "Plot8" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 or MouseTarget.Parent.Parent.Name == "Plot9" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 then
                if TargetSurface.Name == "Top" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y + 2, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y + 4, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Left" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X - 2, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X - 4, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Right" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X + 2, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X + 4, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Back" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z + 2)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z + 4)
                    end
                elseif TargetSurface.Name == "Front" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z - 2)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z - 4)
                    end
                elseif TargetSurface.Name == "Bottom" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y - 2, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y - 4, MouseTarget.Position.Z)
                    end
                end
            end
        end
    end
end)

here is what I tried to do to weld it but it didn't work

local rf = game.ReplicatedStorage.MouseTarget
Build = game.ReplicatedStorage.Build

rf.OnServerEvent:Connect(function(Player, MouseTarget, TargetSurface)
    if MouseTarget.Parent.Parent.Owner.Value == Player.Name then
        local B = Build:Clone()
        B.Parent = MouseTarget.Parent.Parent.Blocks
        if workspace.CanBuild.Value == true then
            if MouseTarget.Parent.Parent.Name == "Plot1" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot2" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot3" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -113 or MouseTarget.Parent.Parent.Name == "Plot4" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -118 or MouseTarget.Parent.Parent.Name == "Plot5" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -175 and MouseTarget.Position.X < -113 or MouseTarget.Parent.Parent.Name == "Plot6" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -31 and MouseTarget.Position.X < 31 or MouseTarget.Parent.Parent.Name == "Plot7" and MouseTarget.Position.Z > -35 and MouseTarget.Position.Z < 27 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 or MouseTarget.Parent.Parent.Name == "Plot8" and MouseTarget.Position.Z > 37 and MouseTarget.Position.Z < 99 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 or MouseTarget.Parent.Parent.Name == "Plot9" and MouseTarget.Position.Z > -107 and MouseTarget.Position.Z < -45 and MouseTarget.Position.X > -103 and MouseTarget.Position.X < -41 then
                if TargetSurface.Name == "Top" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y + 2, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y + 4, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Left" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X - 2, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X - 4, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Right" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X + 2, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X + 4, MouseTarget.Position.Y, MouseTarget.Position.Z)
                    end
                elseif TargetSurface.Name == "Back" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z + 2)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z + 4)
                    end
                elseif TargetSurface.Name == "Front" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z - 2)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y, MouseTarget.Position.Z - 4)
                    end
                elseif TargetSurface.Name == "Bottom" then
                    if MouseTarget.Name == "Part" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y - 2, MouseTarget.Position.Z)
                    elseif MouseTarget.Name == "Build" then
                        B.Position = Vector3.new(MouseTarget.Position.X, MouseTarget.Position.Y - 4, MouseTarget.Position.Z)
                    end
                    wait(.05)
                    B.Touched:Connect(function(part)
                        if part.Name == "Part" or part.Name == "Build" then
                            local  Weld = Instance.new("Weld")
                            Weld.Parent = B
                            Weld.Part0 = B
                            Weld.Part1 = part
                        end
                    end)
                end
            end
        end
    end
end)


0
Something that makes this not work is apparently if the blocks are unanchored they don't work much yasquerda 32 — 3y

Answer this question