Advertisement
Hatman42

Ruler Script - Roblox

Apr 26th, 2019
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. --[[
  2. Name: Ruler
  3. Made by: Hattozo
  4. Description: i know baldi basics is pretty much dead at this point but I wanted to make this
  5. ]]--
  6.  
  7. function sandbox(var,func)
  8. local env = getfenv(func)
  9. local newenv = setmetatable({},{
  10. __index = function(self,k)
  11. if k=="script" then
  12. return var
  13. else
  14. return env[k]
  15. end
  16. end,
  17. })
  18. setfenv(func,newenv)
  19. return func
  20. end
  21. cors = {}
  22. mas = Instance.new("Model",game:GetService("Lighting"))
  23. Tool0 = Instance.new("Tool")
  24. Script1 = Instance.new("Script")
  25. LocalScript2 = Instance.new("LocalScript")
  26. RemoteEvent3 = Instance.new("RemoteEvent")
  27. SpecialMesh4 = Instance.new("SpecialMesh")
  28. Animation5 = Instance.new("Animation")
  29. Camera6 = Instance.new("Camera")
  30. Part7 = Instance.new("Part")
  31. SpecialMesh8 = Instance.new("SpecialMesh")
  32. Decal9 = Instance.new("Decal")
  33. Sound10 = Instance.new("Sound")
  34. Sound11 = Instance.new("Sound")
  35. Tool0.Name = "Ruler"
  36. Tool0.Parent = mas
  37. Tool0.Grip = CFrame.new(-0.300000012, 0.100000001, 0, 0, -0.897135317, -0.441755891, 0.992277861, -0.0547930822, 0.111275934, -0.124034733, -0.438344657, 0.890207469)
  38. Tool0.GripForward = Vector3.new(0.441755891, -0.111275934, -0.890207469)
  39. Tool0.GripPos = Vector3.new(-0.300000012, 0.100000001, 0)
  40. Tool0.GripRight = Vector3.new(0, 0.992277861, -0.124034733)
  41. Tool0.GripUp = Vector3.new(-0.897135317, -0.0547930822, -0.438344657)
  42. Script1.Name = "Server"
  43. Script1.Parent = Tool0
  44. table.insert(cors,sandbox(Script1,function()
  45. local Tool = script.Parent
  46. local Remote = Tool:WaitForChild("Remote")
  47. local Handle = Tool:WaitForChild("Handle")
  48.  
  49. local FriendlyFire = false
  50.  
  51. --local ArmMesh
  52.  
  53. local HitAble = false
  54. local HitWindup = 0.15
  55. local HitWindow = 0.75
  56. local HitDamage = 15
  57. local HitVictims = {}
  58.  
  59. local SwingAble = true
  60. local SwingRestTime = 1
  61.  
  62. --returns the wielding player of this tool
  63. function getPlayer()
  64. local char = Tool.Parent
  65. return game:GetService("Players"):GetPlayerFromCharacter(char)
  66. end
  67.  
  68. --helpfully checks a table for a specific value
  69. function contains(t, v)
  70. for _, val in pairs(t) do
  71. if val == v then
  72. return true
  73. end
  74. end
  75. return false
  76. end
  77.  
  78. --tags a human for the ROBLOX KO system
  79. function tagHuman(human)
  80. local tag = Instance.new("ObjectValue")
  81. tag.Value = getPlayer()
  82. tag.Name = "creator"
  83. tag.Parent = human
  84. game:GetService("Debris"):AddItem(tag)
  85. end
  86.  
  87. --used by checkTeams
  88. function sameTeam(otherHuman)
  89. local player = getPlayer()
  90. local otherPlayer = game:GetService("Players"):GetPlayerFromCharacter(otherHuman.Parent)
  91. if player and otherPlayer then
  92. if player == otherPlayer then
  93. return true
  94. end
  95. if otherPlayer.Neutral then
  96. return false
  97. end
  98. return player.TeamColor == otherPlayer.TeamColor
  99. end
  100. return false
  101. end
  102.  
  103. --use this to determine if you want this human to be harmed or not, returns boolean
  104. function checkTeams(otherHuman)
  105. return not (sameTeam(otherHuman) and not FriendlyFire)
  106. end
  107.  
  108. function onTouched(part)
  109. if part:IsDescendantOf(Tool.Parent) then return end
  110. if not HitAble then return end
  111.  
  112. if part.Parent and part.Parent:FindFirstChild("Humanoid") then
  113. local human = part.Parent.Humanoid
  114.  
  115. if contains(HitVictims, human) then return end
  116.  
  117. local root = part.Parent:FindFirstChild("HumanoidRootPart")
  118. if root and not root.Anchored then
  119. local myRoot = Tool.Parent:FindFirstChild("HumanoidRootPart")
  120. if myRoot and checkTeams(human) then
  121. local delta = root.Position - myRoot.Position
  122.  
  123. human.Sit = true
  124. tagHuman(human)
  125. human:TakeDamage(HitDamage)
  126. table.insert(HitVictims, human)
  127.  
  128. local bv = Instance.new("BodyVelocity")
  129. bv.maxForce = Vector3.new(1e9, 1e9, 1e9)
  130. bv.velocity = delta.unit * 128
  131. bv.Parent = root
  132. game:GetService("Debris"):AddItem(bv, 0.05)
  133.  
  134. Handle.Smack.Pitch = math.random(90, 110)/100
  135. Handle.Smack.TimePosition = 0.15
  136. Handle.Smack:Play()
  137. end
  138. end
  139. end
  140. end
  141.  
  142. --[[function onEquip()
  143. local char = Tool.Parent
  144. local arm = Tool.ArmMesh:Clone()
  145. arm.Parent = char:FindFirstChild("Right Arm")
  146. ArmMesh = arm
  147. end
  148.  
  149. function onUnequip()
  150. if ArmMesh then
  151. ArmMesh:Destroy()
  152. ArmMesh = nil
  153. end
  154. end
  155.  
  156. ]]
  157.  
  158. function onLeftDown()
  159. if not SwingAble then return end
  160.  
  161. SwingAble = false
  162. delay(SwingRestTime, function()
  163. SwingAble = true
  164. end)
  165.  
  166. delay(HitWindup, function()
  167. HitAble = true
  168. delay(HitWindow, function()
  169. HitAble = false
  170. end)
  171. end)
  172.  
  173. HitVictims = {}
  174.  
  175. Remote:FireClient(getPlayer(), "PlayAnimation", "Swing")
  176.  
  177. wait(0.25)
  178. Handle.Boom.Pitch = math.random(80, 100)/100
  179. Handle.Boom:Play()
  180. end
  181.  
  182. function onRemote(player, func, ...)
  183. if player ~= getPlayer() then return end
  184.  
  185. if func == "LeftDown" then
  186. onLeftDown(...)
  187. end
  188. end
  189.  
  190. Tool.Equipped:connect(onEquip)
  191. Tool.Unequipped:connect(onUnequip)
  192. Handle.Touched:connect(onTouched)
  193. Remote.OnServerEvent:connect(onRemote)
  194. end))
  195. LocalScript2.Name = "Client"
  196. LocalScript2.Parent = Tool0
  197. table.insert(cors,sandbox(LocalScript2,function()
  198. local Player = game:GetService("Players").LocalPlayer
  199. local UIS = game:GetService("UserInputService")
  200. local Mouse = Player:GetMouse()
  201. local Tool = script.Parent
  202. local Remote = Tool:WaitForChild("Remote")
  203. local Tracks = {}
  204. local InputType = Enum.UserInputType
  205.  
  206. local BeganConnection, EndedConnection
  207.  
  208. function playAnimation(animName, ...)
  209. if Tracks[animName] then
  210. Tracks[animName]:Play()
  211. else
  212. local anim = Tool:FindFirstChild(animName)
  213. if anim and Tool.Parent and Tool.Parent:FindFirstChild("Humanoid") then
  214. Tracks[animName] = Tool.Parent.Humanoid:LoadAnimation(anim)
  215. playAnimation(animName, ...)
  216. end
  217. end
  218. end
  219.  
  220. function stopAnimation(animName)
  221. if Tracks[animName] then
  222. Tracks[animName]:Stop()
  223. end
  224. end
  225.  
  226. function inputBegan(input)
  227. if input.UserInputType == InputType.MouseButton1 then
  228. Remote:FireServer("LeftDown")
  229. end
  230. end
  231.  
  232. function inputEnded(input)
  233. if input.UserInputType == InputType.MouseButton1 then
  234. Remote:FireServer("LeftUp")
  235. end
  236. end
  237.  
  238. function onRemote(func, ...)
  239. if func == "PlayAnimation" then
  240. playAnimation(...)
  241. elseif func == "StopAnimation" then
  242. stopAnimation(...)
  243. end
  244. end
  245.  
  246. function onEquip()
  247. BeganConnection = UIS.InputBegan:connect(inputBegan)
  248. EndedConnection = UIS.InputEnded:connect(inputEnded)
  249. end
  250.  
  251. function onUnequip()
  252. if BeganConnection then
  253. BeganConnection:disconnect()
  254. BeganConnection = nil
  255. end
  256.  
  257. if EndedConnection then
  258. EndedConnection:disconnect()
  259. EndedConnection = nil
  260. end
  261. end
  262.  
  263. Tool.Equipped:connect(onEquip)
  264. Tool.Unequipped:connect(onUnequip)
  265. Remote.OnClientEvent:connect(onRemote)
  266. end))
  267. RemoteEvent3.Name = "Remote"
  268. RemoteEvent3.Parent = Tool0
  269. SpecialMesh4.Name = "ArmMesh"
  270. SpecialMesh4.Parent = Tool0
  271. SpecialMesh4.MeshId = "http://www.roblox.com/asset/?id=54531127"
  272. SpecialMesh4.TextureId = "http://www.roblox.com/asset/?id=54530630"
  273. SpecialMesh4.MeshType = Enum.MeshType.FileMesh
  274. Animation5.Name = "Swing"
  275. Animation5.Parent = Tool0
  276. Animation5.AnimationId = "rbxassetid://243827693"
  277. Camera6.Name = "ThumbnailCamera"
  278. Camera6.Parent = Tool0
  279. Camera6.CFrame = CFrame.new(-10.3037863, 39.3394203, -3.54806352, 0.0205491576, 0.0850573629, 0.996164203, 1.16415322e-10, 0.996374667, -0.0850753263, -0.99978888, 0.00174822635, 0.0204746593)
  280. Camera6.CoordinateFrame = CFrame.new(-10.3037863, 39.3394203, -3.54806352, 0.0205491576, 0.0850573629, 0.996164203, 1.16415322e-10, 0.996374667, -0.0850753263, -0.99978888, 0.00174822635, 0.0204746593)
  281. Camera6.FieldOfView = 20
  282. Camera6.Focus = CFrame.new(-12.2961159, 39.5095711, -3.58901286, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  283. Camera6.focus = CFrame.new(-12.2961159, 39.5095711, -3.58901286, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  284. Part7.Name = "Handle"
  285. Part7.Parent = Tool0
  286. Part7.CFrame = CFrame.new(12.1999998, 2.41700006, 1.70000005, 8.74227766e-08, -1, -7.57103464e-08, -0.866025388, -3.78551732e-08, -0.5, 0.5, 1.09278474e-07, -0.866025388)
  287. Part7.Orientation = Vector3.new(30, -180, -90)
  288. Part7.Position = Vector3.new(12.1999998, 2.41700006, 1.70000005)
  289. Part7.Rotation = Vector3.new(150, 0, 90)
  290. Part7.Color = Color3.new(0.388235, 0.372549, 0.384314)
  291. Part7.Transparency = 1
  292. Part7.Size = Vector3.new(1, 0.800000012, 5)
  293. Part7.BottomSurface = Enum.SurfaceType.Smooth
  294. Part7.BrickColor = BrickColor.new("Dark stone grey")
  295. Part7.TopSurface = Enum.SurfaceType.Smooth
  296. Part7.brickColor = BrickColor.new("Dark stone grey")
  297. Part7.FormFactor = Enum.FormFactor.Plate
  298. Part7.formFactor = Enum.FormFactor.Plate
  299. SpecialMesh8.Parent = Part7
  300. SpecialMesh8.MeshId = "http://www.roblox.com/asset/?id=10547612"
  301. SpecialMesh8.Scale = Vector3.new(1.79999995, 1.79999995, 1.79999995)
  302. SpecialMesh8.TextureId = "rbxassetid://2231166057"
  303. SpecialMesh8.MeshType = Enum.MeshType.FileMesh
  304. Decal9.Parent = Part7
  305. Decal9.Texture = "http://www.roblox.com/asset/?id=2231166057"
  306. Decal9.Face = Enum.NormalId.Right
  307. Sound10.Name = "Boom"
  308. Sound10.Parent = Part7
  309. Sound10.Pitch = 0.88999998569489
  310. Sound10.PlaybackSpeed = 0.88999998569489
  311. Sound10.SoundId = "rbxassetid://1804495872"
  312. Sound10.Volume = 1
  313. Sound11.Name = "Smack"
  314. Sound11.Parent = Part7
  315. Sound11.SoundId = "rbxassetid://155363126"
  316. for i,v in pairs(mas:GetChildren()) do
  317. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  318. pcall(function() v:MakeJoints() end)
  319. end
  320. mas:Destroy()
  321. for i,v in pairs(cors) do
  322. spawn(function()
  323. pcall(v)
  324. end)
  325. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement