Advertisement
HenloMyDude

piston

Aug 25th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1.  
  2.  
  3. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  4. local Player,game,owner = owner,game
  5. local RealPlayer = Player
  6. do
  7. print("FE Compatibility code V2 by Mokiros")
  8. local RealPlayer = RealPlayer
  9. script.Parent = RealPlayer.Character
  10.  
  11. --Fake event to make stuff like Mouse.KeyDown work
  12. local Disconnect_Function = function(this)
  13. this[1].Functions[this[2]] = nil
  14. end
  15. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  16. local FakeEvent_Metatable = {__index={
  17. Connect = function(this,f)
  18. local i = tostring(math.random(0,10000))
  19. while this.Functions[i] do
  20. i = tostring(math.random(0,10000))
  21. end
  22. this.Functions[i] = f
  23. return setmetatable({this,i},Disconnect_Metatable)
  24. end
  25. }}
  26. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  27. local function fakeEvent()
  28. return setmetatable({Functions={}},FakeEvent_Metatable)
  29. end
  30.  
  31. --Creating fake input objects with fake variables
  32. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  33. FakeMouse.keyUp = FakeMouse.KeyUp
  34. FakeMouse.keyDown = FakeMouse.KeyDown
  35. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  36. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  37. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  38. end}
  39. --Merged 2 functions into one by checking amount of arguments
  40. CAS.UnbindAction = CAS.BindAction
  41.  
  42. --This function will trigger the events that have been :Connect()'ed
  43. local function TriggerEvent(self,ev,...)
  44. for _,f in pairs(self[ev].Functions) do
  45. f(...)
  46. end
  47. end
  48. FakeMouse.TriggerEvent = TriggerEvent
  49. UIS.TriggerEvent = TriggerEvent
  50.  
  51. --Client communication
  52. local Event = Instance.new("RemoteEvent")
  53. Event.Name = "UserInput_Event"
  54. Event.OnServerEvent:Connect(function(plr,io)
  55. if plr~=RealPlayer then return end
  56. FakeMouse.Target = io.Target
  57. FakeMouse.Hit = io.Hit
  58. if not io.isMouse then
  59. local b = io.UserInputState == Enum.UserInputState.Begin
  60. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  61. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  62. end
  63. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  64. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  65. end
  66. for _,t in pairs(CAS.Actions) do
  67. for _,k in pairs(t.Keys) do
  68. if k==io.KeyCode then
  69. t.Function(t.Name,io.UserInputState,io)
  70. end
  71. end
  72. end
  73. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  74. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  75. end
  76. end)
  77. Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  78. local Mouse = owner:GetMouse()
  79. local UIS = game:GetService("UserInputService")
  80. local input = function(io,RobloxHandled)
  81. if RobloxHandled then return end
  82. --Since InputObject is a client-side instance, we create and pass table instead
  83. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  84. end
  85. UIS.InputBegan:Connect(input)
  86. UIS.InputEnded:Connect(input)
  87. local h,t
  88. --Give the server mouse data every second frame, but only if the values changed
  89. --If player is not moving their mouse, client won't fire events
  90. local HB = game:GetService("RunService").Heartbeat
  91. while true do
  92. if h~=Mouse.Hit or t~=Mouse.Target then
  93. h,t=Mouse.Hit,Mouse.Target
  94. Event:FireServer({isMouse=true,Target=t,Hit=h})
  95. end
  96. --Wait 2 frames
  97. for i=1,2 do
  98. HB:Wait()
  99. end
  100. end]==],script)
  101.  
  102. ----Sandboxed game object that allows the usage of client-side methods and services
  103. --Real game object
  104. local RealGame = game
  105.  
  106. --Metatable for fake service
  107. local FakeService_Metatable = {
  108. __index = function(self,k)
  109. local s = rawget(self,"_RealService")
  110. if s then
  111. return typeof(s[k])=="function"
  112. and function(_,...)return s[k](s,...)end or s[k]
  113. end
  114. end,
  115. __newindex = function(self,k,v)
  116. local s = rawget(self,"_RealService")
  117. if s then s[k]=v end
  118. end
  119. }
  120. local function FakeService(t,RealService)
  121. t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  122. return setmetatable(t,FakeService_Metatable)
  123. end
  124.  
  125. --Fake game object
  126. local FakeGame = {
  127. GetService = function(self,s)
  128. return rawget(self,s) or RealGame:GetService(s)
  129. end,
  130. Players = FakeService({
  131. LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  132. },"Players"),
  133. UserInputService = FakeService(UIS,"UserInputService"),
  134. ContextActionService = FakeService(CAS,"ContextActionService"),
  135. RunService = FakeService({
  136. _btrs = {},
  137. RenderStepped = RealGame:GetService("RunService").Heartbeat,
  138. BindToRenderStep = function(self,name,_,fun)
  139. self._btrs[name] = self.Heartbeat:Connect(fun)
  140. end,
  141. UnbindFromRenderStep = function(self,name)
  142. self._btrs[name]:Disconnect()
  143. end,
  144. },"RunService")
  145. }
  146. rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  147. FakeGame.service = FakeGame.GetService
  148. FakeService(FakeGame,game)
  149. --Changing owner to fake player object to support owner:GetMouse()
  150. game,owner = FakeGame,FakeGame.Players.LocalPlayer
  151. end
  152.  
  153.  
  154. plr = owner
  155. char = plr.Character
  156. mouse = plr:GetMouse()
  157. disabled = false
  158.  
  159. function round(n)
  160. return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
  161. end
  162.  
  163. VT = Vector3.new
  164.  
  165. function placepiston()
  166. if disabled == false then
  167. --Converted with ttyyuu12345's model to script plugin v4
  168. function sandbox(var,func)
  169. local env = getfenv(func)
  170. local newenv = setmetatable({},{
  171. __index = function(self,k)
  172. if k=="script" then
  173. return var
  174. else
  175. return env[k]
  176. end
  177. end,
  178. })
  179. setfenv(func,newenv)
  180. return func
  181. end
  182. cors = {}
  183. mas = Instance.new("Model",game:GetService("Lighting"))
  184. Model0 = Instance.new("Model")
  185. Part1 = Instance.new("Part")
  186. Decal2 = Instance.new("Decal")
  187. Decal3 = Instance.new("Decal")
  188. Decal4 = Instance.new("Decal")
  189. Decal5 = Instance.new("Decal")
  190. Decal6 = Instance.new("Decal")
  191. Decal7 = Instance.new("Decal")
  192. Decal8 = Instance.new("Decal")
  193. Weld9 = Instance.new("Weld")
  194. Part10 = Instance.new("Part")
  195. Decal11 = Instance.new("Decal")
  196. Decal12 = Instance.new("Decal")
  197. Decal13 = Instance.new("Decal")
  198. Decal14 = Instance.new("Decal")
  199. Decal15 = Instance.new("Decal")
  200. Part16 = Instance.new("Part")
  201. Decal17 = Instance.new("Decal")
  202. Decal18 = Instance.new("Decal")
  203. Decal19 = Instance.new("Decal")
  204. Decal20 = Instance.new("Decal")
  205. Decal21 = Instance.new("Decal")
  206. Decal22 = Instance.new("Decal")
  207. Model0.Name = "Piston"
  208. Model0.Parent = mas
  209. Part1.Name = "Bottom"
  210. Part1.Parent = Model0
  211. Part1.CFrame = CFrame.new(76.5, 1, 12.5, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  212. Part1.Position = VT(round(mouse.Hit.p.X),round(mouse.Hit.p.Y + 1),round(mouse.Hit.p.Z))
  213. Part1.Size = Vector3.new(3, 2, 3)
  214. Part1.BottomSurface = Enum.SurfaceType.Smooth
  215. Part1.TopSurface = Enum.SurfaceType.Smooth
  216. Decal2.Name = "Piston - Side - Bottom"
  217. Decal2.Parent = Part1
  218. Decal2.Texture = "http://www.roblox.com/asset/?id=151781273"
  219. Decal2.Face = Enum.NormalId.Right
  220. Decal3.Name = "Piston - Side - Bottom"
  221. Decal3.Parent = Part1
  222. Decal3.Texture = "http://www.roblox.com/asset/?id=151781273"
  223. Decal3.Face = Enum.NormalId.Left
  224. Decal4.Name = "Piston - Side - Bottom"
  225. Decal4.Parent = Part1
  226. Decal4.Texture = "http://www.roblox.com/asset/?id=151781273"
  227. Decal4.Face = Enum.NormalId.Left
  228. Decal5.Name = "Piston - Side - Bottom"
  229. Decal5.Parent = Part1
  230. Decal5.Texture = "http://www.roblox.com/asset/?id=151781273"
  231. Decal6.Name = "Piston - Side - Bottom"
  232. Decal6.Parent = Part1
  233. Decal6.Texture = "http://www.roblox.com/asset/?id=151781273"
  234. Decal6.Face = Enum.NormalId.Back
  235. Decal7.Name = "Piston - Side - Bottom"
  236. Decal7.Parent = Part1
  237. Decal7.Texture = "http://www.roblox.com/asset/?id=151781273"
  238. Decal7.Face = Enum.NormalId.Bottom
  239. Decal8.Name = "Piston - Inner"
  240. Decal8.Parent = Part1
  241. Decal8.Texture = "http://www.roblox.com/asset/?id=151781231"
  242. Decal8.Face = Enum.NormalId.Top
  243. Weld9.Name = "BTWeld"
  244. Weld9.Parent = Part1
  245. Weld9.C1 = CFrame.new(0, -1.5, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  246. Weld9.Part0 = Part1
  247. Weld9.Part1 = Part16
  248. Weld9.part1 = Part16
  249. Part10.Name = "Between"
  250. Part10.Parent = Model0
  251. Part10.CFrame = CFrame.new(76.5, 2.4375, 12.5, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  252. Part10.Position = Part16.Position + Vector3.new(0, -0.125, 0)
  253. Part10.Color = Color3.new(0.627451, 0.372549, 0.207843)
  254. Part10.Size = Vector3.new(1, 0.875, 1)
  255. Part10.BottomSurface = Enum.SurfaceType.Smooth
  256. Part10.BrickColor = BrickColor.new("Dark orange")
  257. Part10.TopSurface = Enum.SurfaceType.Smooth
  258. Part10.brickColor = BrickColor.new("Dark orange")
  259. Decal11.Name = "Piston - Side - Top (Fixed)"
  260. Decal11.Parent = Part10
  261. Decal11.Texture = "http://www.roblox.com/asset/?id=151782804"
  262. Decal11.Face = Enum.NormalId.Left
  263. Decal12.Name = "Piston - Side - Top (Fixed)"
  264. Decal12.Parent = Part10
  265. Decal12.Texture = "http://www.roblox.com/asset/?id=151782804"
  266. Decal13.Name = "Piston - Side - Top (Fixed)"
  267. Decal13.Parent = Part10
  268. Decal13.Texture = "http://www.roblox.com/asset/?id=151782804"
  269. Decal13.Face = Enum.NormalId.Right
  270. Decal14.Name = "Piston - Side - Top (Fixed)"
  271. Decal14.Parent = Part10
  272. Decal14.Texture = "http://www.roblox.com/asset/?id=151782804"
  273. Decal14.Face = Enum.NormalId.Back
  274. Decal15.Name = "Piston - Top (Normal)"
  275. Decal15.Parent = Part10
  276. Decal15.Texture = "http://www.roblox.com/asset/?id=151781353"
  277. Decal15.Face = Enum.NormalId.Top
  278. Part16.Name = "Top"
  279. Part16.Parent = Model0
  280. Part16.CFrame = CFrame.new(76.5, 2.5, 12.5, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  281. Part16.Position = Part1.Position + Vector3.new(0, 1.5, 0)
  282. Part16.Color = Color3.new(0.627451, 0.372549, 0.207843)
  283. Part16.Size = Vector3.new(3, 1, 3)
  284. Part16.BottomSurface = Enum.SurfaceType.Smooth
  285. Part16.BrickColor = BrickColor.new("Dark orange")
  286. Part16.TopSurface = Enum.SurfaceType.Smooth
  287. Part16.brickColor = BrickColor.new("Dark orange")
  288. Decal17.Name = "Piston - Side - Top (Fixed)"
  289. Decal17.Parent = Part16
  290. Decal17.Texture = "http://www.roblox.com/asset/?id=151782804"
  291. Decal17.Face = Enum.NormalId.Left
  292. Decal18.Name = "Piston - Side - Top (Fixed)"
  293. Decal18.Parent = Part16
  294. Decal18.Texture = "http://www.roblox.com/asset/?id=151782804"
  295. Decal19.Name = "Piston - Side - Top (Fixed)"
  296. Decal19.Parent = Part16
  297. Decal19.Texture = "http://www.roblox.com/asset/?id=151782804"
  298. Decal19.Face = Enum.NormalId.Right
  299. Decal20.Name = "Piston - Side - Top (Fixed)"
  300. Decal20.Parent = Part16
  301. Decal20.Texture = "http://www.roblox.com/asset/?id=151782804"
  302. Decal20.Face = Enum.NormalId.Back
  303. Decal21.Name = "Piston - Top (Normal)"
  304. Decal21.Parent = Part16
  305. Decal21.Texture = "http://www.roblox.com/asset/?id=151781353"
  306. Decal21.Face = Enum.NormalId.Top
  307. Decal22.Name = "Piston - Top (Normal)"
  308. Decal22.Parent = Part16
  309. Decal22.Texture = "http://www.roblox.com/asset/?id=151781353"
  310. Decal22.Face = Enum.NormalId.Bottom
  311. for i,v in pairs(mas:GetChildren()) do
  312. v.Parent = workspace
  313. pcall(function() v:MakeJoints() end)
  314. end
  315. for i,v in pairs(Model0:GetChildren()) do
  316. v:BreakJoints()
  317. v.Anchored = true
  318. end
  319. mas:Destroy()
  320. for i,v in pairs(cors) do
  321. spawn(function()
  322. pcall(v)
  323. end)
  324. end
  325. end
  326. end
  327.  
  328. lever = false
  329. placedl = false
  330. current = nil
  331.  
  332. function placelever()
  333. if disabled == false then
  334. placedl = true
  335. Model0 = Instance.new("Model",workspace)
  336. Model0.Name = "Lever"
  337. Bottom = Instance.new("Part",Model0)
  338. Bottom.Position = VT(round(mouse.Hit.p.X),round(mouse.Hit.p.Y + 0),round(mouse.Hit.p.Z))
  339. Bottom.Size = Vector3.new(4, 1, 2)
  340. Bottom.Anchored = true
  341. Lever = Instance.new("Part",Model0)
  342. Lever.BrickColor = BrickColor.new("Brown")
  343. Lever.Anchored = true
  344. Lever.Orientation = Vector3.new(0, 0, 2.5)
  345. Lever.Position = Bottom.Position + Vector3.new(0, 1.5, 0)
  346. Lever.Size = Vector3.new(0.5, 2, 0.5)
  347. Lever.Orientation = Vector3.new(0, 0, -25)
  348. Detector = Instance.new("ClickDetector",Lever)
  349. Detector.MaxActivationDistance = 32
  350. ValueT = Instance.new("NumberValue",Lever)
  351. ValueT.Value = 0
  352. function OnClick(player)
  353. if ValueT.Value == 0 then
  354. Lever.Orientation = Vector3.new(0, 0, 25)
  355. ValueT.Value = 1
  356. current.Top.Position = current.Top.Position + Vector3.new(0, 1, 0)
  357. else
  358. Lever.Orientation = Vector3.new(0, 0, -25)
  359. ValueT.Value = 0
  360. current.Top.Position = current.Top.Position - Vector3.new(0, 1, 0)
  361. end
  362. end
  363.  
  364. Detector.MouseClick:connect(function()
  365. OnClick()
  366. end)
  367.  
  368. end
  369. end
  370.  
  371. selecc = Instance.new("Part",char)
  372. selecc.CanCollide = false
  373. selecc.Anchored = true
  374. selecc.BrickColor = BrickColor.new("White")
  375. selecc.Transparency = 0.75
  376. selecc.Material = "SmoothPlastic"
  377. selecc.Size = Vector3.new(3, 3, 3)
  378.  
  379. mouse.Button1Down:connect(function()
  380. placepiston()
  381. end)
  382.  
  383. mouse.KeyDown:connect(function(key)
  384. key=key:lower()
  385. if key == "e" then
  386. if disabled then
  387. disabled = false
  388. selecc.Transparency = 0.75
  389. else
  390. disabled = true
  391. selecc.Transparency = 1
  392. end
  393. end
  394. if key == "l" then
  395. placelever()
  396. end
  397. if key == "r" then
  398. if mouse.Target then
  399. if mouse.Target.Parent.Name == "Piston" then
  400. mouse.Target.Parent:Destroy()
  401. end
  402. if mouse.Target.Parent.Name == "Lever" then
  403. mouse.Target.Parent:Destroy()
  404. end
  405. end
  406. end
  407. if key == "p" then
  408. if mouse.Target then
  409. if mouse.Target.Parent.Name == "Piston" then
  410. current = mouse.Target.Parent
  411. end
  412. end
  413. end
  414. end)
  415.  
  416. while true do
  417. wait()
  418. selecc.Position = VT(round(mouse.Hit.p.X),round(mouse.Hit.p.Y + 1),round(mouse.Hit.p.Z))
  419. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement