Advertisement
StarzoZero

FLASHLIGHT PLZ

Apr 20th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1.  
  2. if game:GetService("RunService"):IsClient()then error("Please run as a server script. Use h/ instead of hl/.")end;print("FE Compatibility: by WaverlyCole");InternalData = {}
  3. do
  4. script.Parent = owner.Character
  5. local Event = Instance.new("RemoteEvent");Event.Name = "UserInput"
  6. local function NewFakeEvent()
  7. local Bind = Instance.new("BindableEvent")
  8. local Fake;Fake = {Connections = {},
  9. fakeEvent=true;
  10. Connect=function(self,Func)
  11. Bind.Event:connect(Func)
  12. self.Connections[Bind] = true
  13. return setmetatable({Connected = true},{
  14. __index = function (self,Index)
  15. if Index:lower() == "disconnect" then
  16. return function() Fake.Connections[Bind] = false;self.Connected = false end
  17. end
  18. return Fake[Index]
  19. end;
  20. __tostring = function() return "Connection" end;
  21. })
  22. end}
  23. Fake.connect = Fake.Connect;return Fake;
  24. end
  25. local Mouse = {Target=nil,Hit=CFrame.new(),KeyUp=NewFakeEvent(),KeyDown=NewFakeEvent(),Button1Up=NewFakeEvent(),Button1Down=NewFakeEvent()}
  26. local UserInputService = {InputBegan=NewFakeEvent(),InputEnded=NewFakeEvent()}
  27. local ContextActionService = {Actions={},BindAction = function(self,actionName,Func,touch,...)
  28. self.Actions[actionName] = Func and {Name=actionName,Function=Func,Keys={...}} or nil
  29. end};ContextActionService.UnBindAction = ContextActionService.BindAction
  30. local function TriggerEvent(self,Event,...)
  31. local Trigger = Mouse[Event]
  32. if Trigger and Trigger.fakeEvent and Trigger.Connections then
  33. for Connection,Active in pairs(Trigger.Connections) do if Active then Connection:Fire(...) end end
  34. end
  35. end
  36. Mouse.TrigEvent = TriggerEvent;UserInputService.TrigEvent = TriggerEvent
  37. Event.OnServerEvent:Connect(function(FiredBy,Input)
  38. if FiredBy.Name ~= owner.Name then return end
  39. if Input.MouseEvent then
  40. Mouse.Target = Input.Target;Mouse.Hit = Input.Hit
  41. else
  42. local Begin = Input.UserInputState == Enum.UserInputState.Begin
  43. if Input.UserInputType == Enum.UserInputType.MouseButton1 then return Mouse:TrigEvent(Begin and "Button1Down" or "Button1Up") end
  44. for _,Action in pairs(ContextActionService.Actions) do
  45. for _,Key in pairs(Action.Keys) do if Key==Input.KeyCode then Action.Function(Action.Name,Input.UserInputState,Input) end end
  46. end
  47. Mouse:TrigEvent(Begin and "KeyDown" or "KeyUp",Input.KeyCode.Name:lower())
  48. UserInputService:TrigEvent(Begin and "InputBegan" or "InputEnded",Input,false)
  49. end
  50. end)
  51. InternalData["Mouse"] = Mouse;InternalData["ContextActionService"] = ContextActionService;InternalData["UserInputService"] = UserInputService
  52. Event.Parent = NLS([[
  53. local Player = owner;local Event = script:WaitForChild("UserInput");local UserInputService = game:GetService("UserInputService");local Mouse = Player:GetMouse()
  54. local Input = function(Input,gameProcessedEvent)
  55. if gameProcessedEvent then return end
  56. Event:FireServer({KeyCode=Input.KeyCode,UserInputType=Input.UserInputType,UserInputState=Input.UserInputState})
  57. end
  58. UserInputService.InputBegan:Connect(Input);UserInputService.InputEnded:Connect(Input)
  59. local Hit,Target
  60. while wait(1/30) do
  61. if Hit ~= Mouse.Hit or Target ~= Mouse.Target then
  62. Hit,Target = Mouse.Hit,Mouse.Target;Event:FireServer({["MouseEvent"]=true,["Target"]=Target,["Hit"]=Hit})
  63. end
  64. end
  65. ]],owner.Character)
  66. end
  67. RealGame = game;game = setmetatable({},{
  68. __index = function (self,Index)
  69. local Sandbox = function (Thing)
  70. if Thing:IsA("Player") then
  71. local RealPlayer = Thing
  72. return setmetatable({},{
  73. __index = function (self,Index)
  74. local Type = type(RealPlayer[Index])
  75. if Type == "function" then
  76. if Index:lower() == "getmouse" or Index:lower() == "mouse" then
  77. return function (self)return InternalData["Mouse"] end
  78. end
  79. return function (self,...)return RealPlayer[Index](RealPlayer,...) end
  80. end
  81. return RealPlayer[Index]
  82. end;
  83. __tostring = function(self) return RealPlayer.Name end
  84. })
  85. end
  86. end
  87. if RealGame[Index] then
  88. local Type = type(RealGame[Index])
  89. if Type == "function" then
  90. if Index:lower() == "getservice" or Index:lower() == "service" then
  91. return function (self,Service)
  92. local FakeServices = {
  93. ["players"] = function()
  94. return setmetatable({},{
  95. __index = function (self2,Index2)
  96. local RealService = RealGame:GetService(Service)
  97. local Type2 = type(Index2)
  98. if Type2 == "function" then
  99. return function (self,...) return RealService[Index2](RealService,...)end
  100. else
  101. if Index2:lower() == "localplayer" then return Sandbox(owner) end
  102. return RealService[Index2]
  103. end
  104. end;
  105. __tostring = function(self) return RealGame:GetService(Service).Name end
  106. })
  107. end;
  108. ["contextactionservice"] = function() return InternalData["ContextActionService"] end;
  109. ["userinputservice"] = function() return InternalData["UserInputService"] end;
  110. ["runservice"] = function()
  111. return setmetatable({},{
  112. __index = function(self2,Index2)
  113. local RealService = RealGame:GetService(Service)
  114. local Type2 = type(Index2)
  115. if Type2 == "function" then
  116. return function (self,...) return RealService[Index2](RealService,...) end
  117. else
  118. local RunServices = {
  119. ["bindtorenderstep"] = function() return function (self,Name,Priority,Function) return RealGame:GetService("RunService").Stepped:Connect(Function) end end;
  120. ["renderstepped"] = function() return RealService["Stepped"] end
  121. }
  122. if RunServices[Index2:lower()] then return RunServices[Index2:lower()]() end
  123. return RealService[Index2]
  124. end
  125. end
  126. })
  127. end
  128. }
  129. if FakeServices[Service:lower()] then return FakeServices[Service:lower()]() end
  130. return RealGame:GetService(Service)
  131. end
  132. end
  133. return function (self,...) return RealGame[Index](RealGame,...) end
  134. else
  135. if game:GetService(Index) then return game:GetService(Index) end
  136. return RealGame[Index]
  137. end
  138. end
  139. return nil
  140. end
  141. });Game = game;owner = game:GetService("Players").LocalPlayer;script = Instance.new("Script");print("Complete! Running...")
  142.  
  143. -- Created by supersonicfan111
  144. local p=game:GetService"Players".LocalPlayer
  145. local c=p.Character
  146. local surf='SmoothNoOutlines'
  147. if not c then error'Cannot find character, please respawn, then rerun the script' end
  148.  
  149. -- Flashlight Handle
  150. local hand=Instance.new"Part"
  151. hand.BrickColor=BrickColor.DarkGray()
  152. hand.Parent=c
  153. hand.Anchored=false
  154. hand.Locked=true
  155. hand.CanCollide=false
  156. hand.FormFactor='Custom'
  157. hand.Size=Vector3.new(1,1,2)
  158. hand.TopSurface,hand.BottomSurface=surf,surf
  159.  
  160. -- Torch Effect
  161. local fe=Instance.new"Part"
  162. fe.BrickColor=BrickColor.new"Black"
  163. fe.Parent=c
  164. fe.Anchored=false
  165. fe.Locked=true
  166. fe.CanCollide=false
  167. fe.FormFactor='Custom'
  168. fe.Size=Vector3.new(.8,.8,.2)
  169. fe.TopSurface,hand.BottomSurface=surf,surf
  170.  
  171. -- Welding stuff
  172.  
  173. -- Flash to Right Arm
  174. local weld1=Instance.new"Weld"
  175. weld1.Parent=hand
  176. weld1.Part0=hand
  177. weld1.Part1=c['Right Arm']
  178. weld1.C0=CFrame.new(0, 1.5, 0)
  179.  
  180. -- Torch Effect to Flash
  181. local weld2=Instance.new"Weld"
  182. weld2.Parent=hand
  183. weld2.Part0=hand
  184. weld2.Part1=fe
  185. weld2.C0=CFrame.new(0, 0, 1)
  186.  
  187. -- Right Arm Weld
  188. local ra=Instance.new"Weld"
  189. ra.Parent=c['Torso']
  190. ra.Part0=c['Right Arm']
  191. ra.Part1=c['Torso']
  192. ra.C0=CFrame.new(-1.5,1,0)*CFrame.Angles(math.rad(180),0,0)
  193.  
  194.  
  195.  
  196. -- Flashlight Functionality
  197.  
  198. local flashlightOn = false
  199. local Battery=100
  200.  
  201. -- Handles turning the flashlight on/off
  202. p:GetMouse().Button1Down:connect(function()
  203. flashlightOn=not flashlightOn
  204. if flashlightOn then
  205. fe.BrickColor=BrickColor.new"New Yeller"
  206. light=Instance.new"SurfaceLight"
  207. light.Parent=fe
  208. light.Range=32
  209. light.Face="Back"
  210. light.Brightness=2
  211. fe.Material="Neon"
  212. else
  213. fe.BrickColor=BrickColor.new"Black"
  214. if light then light:destroy() end
  215. fe.Material="SmoothPlastic"
  216. end
  217. end)
  218.  
  219. -- Battery Modules
  220.  
  221. -- Depleting and Charging
  222. spawn(function()
  223. while wait(1) do
  224. if flashlightOn then
  225. if Battery > 0 then
  226. Battery=Battery-1
  227. end
  228. else
  229. if Battery < 100 then
  230. Battery=Battery+1
  231. end
  232. end
  233. print(Battery)
  234. end
  235. end)
  236.  
  237. -- Turning off flashlight if the battery is too low
  238. spawn(function()
  239. while wait() do
  240. if Battery <= 0 then
  241. flashlightOn=false
  242. if light then light:destroy() end
  243. fe.BrickColor=BrickColor.new"Black"
  244. fe.Material="SmoothPlastic"
  245. end
  246. end
  247. end)
  248.  
  249. local stepped = game:GetService'RunService'.RenderStepped
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement