Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Converted with ttyyuu12345's model to script plugin v4
- function sandbox(var,func)
- local env = getfenv(func)
- local newenv = setmetatable({},{
- __index = function(self,k)
- if k=="script" then
- return var
- else
- return env[k]
- end
- end,
- })
- setfenv(func,newenv)
- return func
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- Tool0 = Instance.new("Tool")
- Part1 = Instance.new("Part")
- Part2 = Instance.new("Part")
- Part3 = Instance.new("Part")
- Script4 = Instance.new("Script")
- LocalScript5 = Instance.new("LocalScript")
- RemoteEvent6 = Instance.new("RemoteEvent")
- RemoteEvent7 = Instance.new("RemoteEvent")
- Tool0.Name = "Wand"
- Tool0.Parent = mas
- Tool0.ToolTip = "This Is A Wand.."
- Part1.Name = "Handle"
- Part1.Parent = Tool0
- Part1.Size = Vector3.new(0.919999957, 2.72999954, 0.880000055)
- Part1.CFrame = CFrame.new(1.75, 1.36500394, 3.29999995, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part1.BackSurface = Enum.SurfaceType.Weld
- Part1.BottomSurface = Enum.SurfaceType.Smooth
- Part1.FrontSurface = Enum.SurfaceType.Weld
- Part1.LeftSurface = Enum.SurfaceType.Weld
- Part1.RightSurface = Enum.SurfaceType.Weld
- Part1.TopSurface = Enum.SurfaceType.Smooth
- Part1.Position = Vector3.new(1.75, 1.36500394, 3.29999995)
- Part2.Parent = Tool0
- Part2.Material = Enum.Material.Wood
- Part2.BrickColor = BrickColor.new("Rust")
- Part2.Size = Vector3.new(0.919999957, 2.72999954, 0.880000055)
- Part2.CFrame = CFrame.new(1.75, 4.09500217, 3.29999995, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part2.BackSurface = Enum.SurfaceType.Weld
- Part2.BottomSurface = Enum.SurfaceType.Smooth
- Part2.FrontSurface = Enum.SurfaceType.Weld
- Part2.LeftSurface = Enum.SurfaceType.Weld
- Part2.RightSurface = Enum.SurfaceType.Weld
- Part2.TopSurface = Enum.SurfaceType.Smooth
- Part2.Color = Color3.new(0.560784, 0.298039, 0.164706)
- Part2.Position = Vector3.new(1.75, 4.09500217, 3.29999995)
- Part2.Color = Color3.new(0.560784, 0.298039, 0.164706)
- Part3.Parent = Tool0
- Part3.Material = Enum.Material.Neon
- Part3.BrickColor = BrickColor.new("Magenta")
- Part3.Size = Vector3.new(0.950000167, 1, 0.889999747)
- Part3.CFrame = CFrame.new(1.80499995, 5.95999908, 3.33500004, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part3.BackSurface = Enum.SurfaceType.Weld
- Part3.BottomSurface = Enum.SurfaceType.Smooth
- Part3.FrontSurface = Enum.SurfaceType.Weld
- Part3.LeftSurface = Enum.SurfaceType.Weld
- Part3.RightSurface = Enum.SurfaceType.Weld
- Part3.TopSurface = Enum.SurfaceType.Weld
- Part3.Color = Color3.new(0.666667, 0, 0.666667)
- Part3.Position = Vector3.new(1.80499995, 5.95999908, 3.33500004)
- Part3.Color = Color3.new(0.666667, 0, 0.666667)
- Script4.Name = "qPerfectionWeld"
- Script4.Parent = Tool0
- table.insert(cors,sandbox(Script4,function()
- -- Created by Quenty (@Quenty, follow me on twitter).
- -- Should work with only ONE copy, seamlessly with weapons, trains, et cetera.
- -- Parts should be ANCHORED before use. It will, however, store relatives values and so when tools are reparented, it'll fix them.
- --[[ INSTRUCTIONS
- - Place in the model
- - Make sure model is anchored
- - That's it. It will weld the model and all children.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- This script is designed to be used is a regular script. In a local script it will weld, but it will not attempt to handle ancestory changes.
- ]]
- --[[ DOCUMENTATION
- - Will work in tools. If ran more than once it will not create more than one weld. This is especially useful for tools that are dropped and then picked up again.
- - Will work in PBS servers
- - Will work as long as it starts out with the part anchored
- - Stores the relative CFrame as a CFrame value
- - Takes careful measure to reduce lag by not having a joint set off or affected by the parts offset from origin
- - Utilizes a recursive algorith to find all parts in the model
- - Will reweld on script reparent if the script is initially parented to a tool.
- - Welds as fast as possible
- ]]
- -- qPerfectionWeld.lua
- -- Created 10/6/2014
- -- Author: Quenty
- -- Version 1.0.3
- -- Updated 10/14/2014 - Updated to 1.0.1
- --- Bug fix with existing ROBLOX welds ? Repro by asimo3089
- -- Updated 10/14/2014 - Updated to 1.0.2
- --- Fixed bug fix.
- -- Updated 10/14/2014 - Updated to 1.0.3
- --- Now handles joints semi-acceptably. May be rather hacky with some joints. :/
- local NEVER_BREAK_JOINTS = false -- If you set this to true it will never break joints (this can create some welding issues, but can save stuff like hinges).
- local function CallOnChildren(Instance, FunctionToCall)
- -- Calls a function on each of the children of a certain object, using recursion.
- FunctionToCall(Instance)
- for _, Child in next, Instance:GetChildren() do
- CallOnChildren(Child, FunctionToCall)
- end
- end
- local function GetNearestParent(Instance, ClassName)
- -- Returns the nearest parent of a certain class, or returns nil
- local Ancestor = Instance
- repeat
- Ancestor = Ancestor.Parent
- if Ancestor == nil then
- return nil
- end
- until Ancestor:IsA(ClassName)
- return Ancestor
- end
- local function GetBricks(StartInstance)
- local List = {}
- -- if StartInstance:IsA("BasePart") then
- -- List[#List+1] = StartInstance
- -- end
- CallOnChildren(StartInstance, function(Item)
- if Item:IsA("BasePart") then
- List[#List+1] = Item;
- end
- end)
- return List
- end
- local function Modify(Instance, Values)
- -- Modifies an Instance by using a table.
- assert(type(Values) == "table", "Values is not a table");
- for Index, Value in next, Values do
- if type(Index) == "number" then
- Value.Parent = Instance
- else
- Instance[Index] = Value
- end
- end
- return Instance
- end
- local function Make(ClassType, Properties)
- -- Using a syntax hack to create a nice way to Make new items.
- return Modify(Instance.new(ClassType), Properties)
- end
- local Surfaces = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}
- local HingSurfaces = {"Hinge", "Motor", "SteppingMotor"}
- local function HasWheelJoint(Part)
- for _, SurfaceName in pairs(Surfaces) do
- for _, HingSurfaceName in pairs(HingSurfaces) do
- if Part[SurfaceName].Name == HingSurfaceName then
- return true
- end
- end
- end
- return false
- end
- local function ShouldBreakJoints(Part)
- --- We do not want to break joints of wheels/hinges. This takes the utmost care to not do this. There are
- -- definitely some edge cases.
- if NEVER_BREAK_JOINTS then
- return false
- end
- if HasWheelJoint(Part) then
- return false
- end
- local Connected = Part:GetConnectedParts()
- if #Connected == 1 then
- return false
- end
- for _, Item in pairs(Connected) do
- if HasWheelJoint(Item) then
- return false
- elseif not Item:IsDescendantOf(script.Parent) then
- return false
- end
- end
- return true
- end
- local function WeldTogether(Part0, Part1, JointType, WeldParent)
- --- Weld's 2 parts together
- -- @param Part0 The first part
- -- @param Part1 The second part (Dependent part most of the time).
- -- @param [JointType] The type of joint. Defaults to weld.
- -- @param [WeldParent] Parent of the weld, Defaults to Part0 (so GC is better).
- -- @return The weld created.
- JointType = JointType or "Weld"
- local RelativeValue = Part1:FindFirstChild("qRelativeCFrameWeldValue")
- local NewWeld = Part1:FindFirstChild("qCFrameWeldThingy") or Instance.new(JointType)
- Modify(NewWeld, {
- Name = "qCFrameWeldThingy";
- Part0 = Part0;
- Part1 = Part1;
- C0 = CFrame.new();--Part0.CFrame:inverse();
- C1 = RelativeValue and RelativeValue.Value or Part1.CFrame:toObjectSpace(Part0.CFrame); --Part1.CFrame:inverse() * Part0.CFrame;-- Part1.CFrame:inverse();
- Parent = Part1;
- })
- if not RelativeValue then
- RelativeValue = Make("CFrameValue", {
- Parent = Part1;
- Name = "qRelativeCFrameWeldValue";
- Archivable = true;
- Value = NewWeld.C1;
- })
- end
- return NewWeld
- end
- local function WeldParts(Parts, MainPart, JointType, DoNotUnanchor)
- -- @param Parts The Parts to weld. Should be anchored to prevent really horrible results.
- -- @param MainPart The part to weld the model to (can be in the model).
- -- @param [JointType] The type of joint. Defaults to weld.
- -- @parm DoNotUnanchor Boolean, if true, will not unachor the model after cmopletion.
- for _, Part in pairs(Parts) do
- if ShouldBreakJoints(Part) then
- Part:BreakJoints()
- end
- end
- for _, Part in pairs(Parts) do
- if Part ~= MainPart then
- WeldTogether(MainPart, Part, JointType, MainPart)
- end
- end
- if not DoNotUnanchor then
- for _, Part in pairs(Parts) do
- Part.Anchored = false
- end
- MainPart.Anchored = false
- end
- end
- local function PerfectionWeld()
- local Tool = GetNearestParent(script, "Tool")
- local Parts = GetBricks(script.Parent)
- local PrimaryPart = Tool and Tool:FindFirstChild("Handle") and Tool.Handle:IsA("BasePart") and Tool.Handle or script.Parent:IsA("Model") and script.Parent.PrimaryPart or Parts[1]
- if PrimaryPart then
- WeldParts(Parts, PrimaryPart, "Weld", false)
- else
- warn("qWeld - Unable to weld part")
- end
- return Tool
- end
- local Tool = PerfectionWeld()
- if Tool and script.ClassName == "Script" then
- --- Don't bother with local scripts
- script.Parent.AncestryChanged:connect(function()
- PerfectionWeld()
- end)
- end
- -- Created by Quenty (@Quenty, follow me on twitter).
- end))
- LocalScript5.Name = "WandMain"
- LocalScript5.Parent = Tool0
- table.insert(cors,sandbox(LocalScript5,function()
- -- This code assumes the script is directly inside the tool. If the script is elsewhere, you will have to change the path the next variable is pointing to.
- local tool = script.Parent
- local function onEquip()
- script.Parent.EquipEvent:FireServer()
- print("Tool Has Loded")
- end
- local function onUnequip()
- end
- local function onActivate()
- script.Parent.ClickEvent:FireServer()
- while true do
- wait(0)
- Instance.new("Part",game.Workspace)
- end
- end
- local function onDeactivate()
- end
- tool.Equipped:connect(onEquip)
- tool.Unequipped:connect(onUnequip)
- tool.Activated:connect(onActivate)
- tool.Deactivated:connect(onDeactivate)
- end))
- RemoteEvent6.Name = "ClickEvent"
- RemoteEvent6.Parent = Tool0
- RemoteEvent7.Name = "EquipEvent"
- RemoteEvent7.Parent = Tool0
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = game:GetService("Players").LocalPlayer.Backpack
- pcall(function() v:MakeJoints() end)
- end
- mas:Destroy()
- for i,v in pairs(cors) do
- spawn(function()
- pcall(v)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement