Advertisement
memberhero

Wand script

Dec 13th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.89 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Tool0 = Instance.new("Tool")
  20. Part1 = Instance.new("Part")
  21. Part2 = Instance.new("Part")
  22. Part3 = Instance.new("Part")
  23. Script4 = Instance.new("Script")
  24. LocalScript5 = Instance.new("LocalScript")
  25. RemoteEvent6 = Instance.new("RemoteEvent")
  26. RemoteEvent7 = Instance.new("RemoteEvent")
  27. Tool0.Name = "Wand"
  28. Tool0.Parent = mas
  29. Tool0.ToolTip = "This Is A Wand.."
  30. Part1.Name = "Handle"
  31. Part1.Parent = Tool0
  32. Part1.Size = Vector3.new(0.919999957, 2.72999954, 0.880000055)
  33. Part1.CFrame = CFrame.new(1.75, 1.36500394, 3.29999995, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  34. Part1.BackSurface = Enum.SurfaceType.Weld
  35. Part1.BottomSurface = Enum.SurfaceType.Smooth
  36. Part1.FrontSurface = Enum.SurfaceType.Weld
  37. Part1.LeftSurface = Enum.SurfaceType.Weld
  38. Part1.RightSurface = Enum.SurfaceType.Weld
  39. Part1.TopSurface = Enum.SurfaceType.Smooth
  40. Part1.Position = Vector3.new(1.75, 1.36500394, 3.29999995)
  41. Part2.Parent = Tool0
  42. Part2.Material = Enum.Material.Wood
  43. Part2.BrickColor = BrickColor.new("Rust")
  44. Part2.Size = Vector3.new(0.919999957, 2.72999954, 0.880000055)
  45. Part2.CFrame = CFrame.new(1.75, 4.09500217, 3.29999995, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  46. Part2.BackSurface = Enum.SurfaceType.Weld
  47. Part2.BottomSurface = Enum.SurfaceType.Smooth
  48. Part2.FrontSurface = Enum.SurfaceType.Weld
  49. Part2.LeftSurface = Enum.SurfaceType.Weld
  50. Part2.RightSurface = Enum.SurfaceType.Weld
  51. Part2.TopSurface = Enum.SurfaceType.Smooth
  52. Part2.Color = Color3.new(0.560784, 0.298039, 0.164706)
  53. Part2.Position = Vector3.new(1.75, 4.09500217, 3.29999995)
  54. Part2.Color = Color3.new(0.560784, 0.298039, 0.164706)
  55. Part3.Parent = Tool0
  56. Part3.Material = Enum.Material.Neon
  57. Part3.BrickColor = BrickColor.new("Magenta")
  58. Part3.Size = Vector3.new(0.950000167, 1, 0.889999747)
  59. Part3.CFrame = CFrame.new(1.80499995, 5.95999908, 3.33500004, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  60. Part3.BackSurface = Enum.SurfaceType.Weld
  61. Part3.BottomSurface = Enum.SurfaceType.Smooth
  62. Part3.FrontSurface = Enum.SurfaceType.Weld
  63. Part3.LeftSurface = Enum.SurfaceType.Weld
  64. Part3.RightSurface = Enum.SurfaceType.Weld
  65. Part3.TopSurface = Enum.SurfaceType.Weld
  66. Part3.Color = Color3.new(0.666667, 0, 0.666667)
  67. Part3.Position = Vector3.new(1.80499995, 5.95999908, 3.33500004)
  68. Part3.Color = Color3.new(0.666667, 0, 0.666667)
  69. Script4.Name = "qPerfectionWeld"
  70. Script4.Parent = Tool0
  71. table.insert(cors,sandbox(Script4,function()
  72. -- Created by Quenty (@Quenty, follow me on twitter).
  73. -- Should work with only ONE copy, seamlessly with weapons, trains, et cetera.
  74. -- Parts should be ANCHORED before use. It will, however, store relatives values and so when tools are reparented, it'll fix them.
  75.  
  76. --[[ INSTRUCTIONS
  77. - Place in the model
  78. - Make sure model is anchored
  79. - That's it. It will weld the model and all children.
  80.  
  81. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  82. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  83. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  84. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  85. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  86. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  87. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  88. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  89.  
  90. 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.
  91. ]]
  92.  
  93. --[[ DOCUMENTATION
  94. - 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.
  95. - Will work in PBS servers
  96. - Will work as long as it starts out with the part anchored
  97. - Stores the relative CFrame as a CFrame value
  98. - Takes careful measure to reduce lag by not having a joint set off or affected by the parts offset from origin
  99. - Utilizes a recursive algorith to find all parts in the model
  100. - Will reweld on script reparent if the script is initially parented to a tool.
  101. - Welds as fast as possible
  102. ]]
  103.  
  104. -- qPerfectionWeld.lua
  105. -- Created 10/6/2014
  106. -- Author: Quenty
  107. -- Version 1.0.3
  108.  
  109. -- Updated 10/14/2014 - Updated to 1.0.1
  110. --- Bug fix with existing ROBLOX welds ? Repro by asimo3089
  111.  
  112. -- Updated 10/14/2014 - Updated to 1.0.2
  113. --- Fixed bug fix.
  114.  
  115. -- Updated 10/14/2014 - Updated to 1.0.3
  116. --- Now handles joints semi-acceptably. May be rather hacky with some joints. :/
  117.  
  118. 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).
  119.  
  120.  
  121. local function CallOnChildren(Instance, FunctionToCall)
  122. -- Calls a function on each of the children of a certain object, using recursion.
  123.  
  124. FunctionToCall(Instance)
  125.  
  126. for _, Child in next, Instance:GetChildren() do
  127. CallOnChildren(Child, FunctionToCall)
  128. end
  129. end
  130.  
  131. local function GetNearestParent(Instance, ClassName)
  132. -- Returns the nearest parent of a certain class, or returns nil
  133.  
  134. local Ancestor = Instance
  135. repeat
  136. Ancestor = Ancestor.Parent
  137. if Ancestor == nil then
  138. return nil
  139. end
  140. until Ancestor:IsA(ClassName)
  141.  
  142. return Ancestor
  143. end
  144.  
  145. local function GetBricks(StartInstance)
  146. local List = {}
  147.  
  148. -- if StartInstance:IsA("BasePart") then
  149. -- List[#List+1] = StartInstance
  150. -- end
  151.  
  152. CallOnChildren(StartInstance, function(Item)
  153. if Item:IsA("BasePart") then
  154. List[#List+1] = Item;
  155. end
  156. end)
  157.  
  158. return List
  159. end
  160.  
  161. local function Modify(Instance, Values)
  162. -- Modifies an Instance by using a table.
  163.  
  164. assert(type(Values) == "table", "Values is not a table");
  165.  
  166. for Index, Value in next, Values do
  167. if type(Index) == "number" then
  168. Value.Parent = Instance
  169. else
  170. Instance[Index] = Value
  171. end
  172. end
  173. return Instance
  174. end
  175.  
  176. local function Make(ClassType, Properties)
  177. -- Using a syntax hack to create a nice way to Make new items.
  178.  
  179. return Modify(Instance.new(ClassType), Properties)
  180. end
  181.  
  182. local Surfaces = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}
  183. local HingSurfaces = {"Hinge", "Motor", "SteppingMotor"}
  184.  
  185. local function HasWheelJoint(Part)
  186. for _, SurfaceName in pairs(Surfaces) do
  187. for _, HingSurfaceName in pairs(HingSurfaces) do
  188. if Part[SurfaceName].Name == HingSurfaceName then
  189. return true
  190. end
  191. end
  192. end
  193.  
  194. return false
  195. end
  196.  
  197. local function ShouldBreakJoints(Part)
  198. --- We do not want to break joints of wheels/hinges. This takes the utmost care to not do this. There are
  199. -- definitely some edge cases.
  200.  
  201. if NEVER_BREAK_JOINTS then
  202. return false
  203. end
  204.  
  205. if HasWheelJoint(Part) then
  206. return false
  207. end
  208.  
  209. local Connected = Part:GetConnectedParts()
  210.  
  211. if #Connected == 1 then
  212. return false
  213. end
  214.  
  215. for _, Item in pairs(Connected) do
  216. if HasWheelJoint(Item) then
  217. return false
  218. elseif not Item:IsDescendantOf(script.Parent) then
  219. return false
  220. end
  221. end
  222.  
  223. return true
  224. end
  225.  
  226. local function WeldTogether(Part0, Part1, JointType, WeldParent)
  227. --- Weld's 2 parts together
  228. -- @param Part0 The first part
  229. -- @param Part1 The second part (Dependent part most of the time).
  230. -- @param [JointType] The type of joint. Defaults to weld.
  231. -- @param [WeldParent] Parent of the weld, Defaults to Part0 (so GC is better).
  232. -- @return The weld created.
  233.  
  234. JointType = JointType or "Weld"
  235. local RelativeValue = Part1:FindFirstChild("qRelativeCFrameWeldValue")
  236.  
  237. local NewWeld = Part1:FindFirstChild("qCFrameWeldThingy") or Instance.new(JointType)
  238. Modify(NewWeld, {
  239. Name = "qCFrameWeldThingy";
  240. Part0 = Part0;
  241. Part1 = Part1;
  242. C0 = CFrame.new();--Part0.CFrame:inverse();
  243. C1 = RelativeValue and RelativeValue.Value or Part1.CFrame:toObjectSpace(Part0.CFrame); --Part1.CFrame:inverse() * Part0.CFrame;-- Part1.CFrame:inverse();
  244. Parent = Part1;
  245. })
  246.  
  247. if not RelativeValue then
  248. RelativeValue = Make("CFrameValue", {
  249. Parent = Part1;
  250. Name = "qRelativeCFrameWeldValue";
  251. Archivable = true;
  252. Value = NewWeld.C1;
  253. })
  254. end
  255.  
  256. return NewWeld
  257. end
  258.  
  259. local function WeldParts(Parts, MainPart, JointType, DoNotUnanchor)
  260. -- @param Parts The Parts to weld. Should be anchored to prevent really horrible results.
  261. -- @param MainPart The part to weld the model to (can be in the model).
  262. -- @param [JointType] The type of joint. Defaults to weld.
  263. -- @parm DoNotUnanchor Boolean, if true, will not unachor the model after cmopletion.
  264.  
  265. for _, Part in pairs(Parts) do
  266. if ShouldBreakJoints(Part) then
  267. Part:BreakJoints()
  268. end
  269. end
  270.  
  271. for _, Part in pairs(Parts) do
  272. if Part ~= MainPart then
  273. WeldTogether(MainPart, Part, JointType, MainPart)
  274. end
  275. end
  276.  
  277. if not DoNotUnanchor then
  278. for _, Part in pairs(Parts) do
  279. Part.Anchored = false
  280. end
  281. MainPart.Anchored = false
  282. end
  283. end
  284.  
  285. local function PerfectionWeld()
  286. local Tool = GetNearestParent(script, "Tool")
  287.  
  288. local Parts = GetBricks(script.Parent)
  289. 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]
  290.  
  291. if PrimaryPart then
  292. WeldParts(Parts, PrimaryPart, "Weld", false)
  293. else
  294. warn("qWeld - Unable to weld part")
  295. end
  296.  
  297. return Tool
  298. end
  299.  
  300. local Tool = PerfectionWeld()
  301.  
  302.  
  303. if Tool and script.ClassName == "Script" then
  304. --- Don't bother with local scripts
  305.  
  306. script.Parent.AncestryChanged:connect(function()
  307. PerfectionWeld()
  308. end)
  309. end
  310.  
  311. -- Created by Quenty (@Quenty, follow me on twitter).
  312.  
  313. end))
  314. LocalScript5.Name = "WandMain"
  315. LocalScript5.Parent = Tool0
  316. table.insert(cors,sandbox(LocalScript5,function()
  317. -- 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.
  318. local tool = script.Parent
  319.  
  320. local function onEquip()
  321. script.Parent.EquipEvent:FireServer()
  322. print("Tool Has Loded")
  323. end
  324.  
  325. local function onUnequip()
  326.  
  327. end
  328.  
  329. local function onActivate()
  330. script.Parent.ClickEvent:FireServer()
  331. while true do
  332. wait(0)
  333. Instance.new("Part",game.Workspace)
  334.  
  335. end
  336. end
  337.  
  338. local function onDeactivate()
  339.  
  340. end
  341.  
  342. tool.Equipped:connect(onEquip)
  343. tool.Unequipped:connect(onUnequip)
  344. tool.Activated:connect(onActivate)
  345. tool.Deactivated:connect(onDeactivate)
  346. end))
  347. RemoteEvent6.Name = "ClickEvent"
  348. RemoteEvent6.Parent = Tool0
  349. RemoteEvent7.Name = "EquipEvent"
  350. RemoteEvent7.Parent = Tool0
  351. for i,v in pairs(mas:GetChildren()) do
  352. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  353. pcall(function() v:MakeJoints() end)
  354. end
  355. mas:Destroy()
  356. for i,v in pairs(cors) do
  357. spawn(function()
  358. pcall(v)
  359. end)
  360. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement