JacksoMykalJunior

CWESTENIA

Mar 1st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  2. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  3. do
  4. print("FE made by Red_Jack142")
  5. script.Parent = Player.Character
  6.  
  7. --RemoteEvent for communicating
  8. local Event = Instance.new("RemoteEvent")
  9. Event.Name = "UserInput_Event"
  10.  
  11. --Fake event to make stuff like Mouse.KeyDown work
  12. local function fakeEvent()
  13. local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
  14. t.connect = t.Connect
  15. return t
  16. end
  17.  
  18. --Creating fake input objects with fake variables
  19. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  20. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  21. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  22. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  23. end}
  24. --Merged 2 functions into one by checking amount of arguments
  25. CAS.UnbindAction = CAS.BindAction
  26.  
  27. --This function will trigger the events that have been :Connect()'ed
  28. local function te(self,ev,...)
  29. local t = m[ev]
  30. if t and t._fakeEvent and t.Function then
  31. t.Function(...)
  32. end
  33. end
  34. m.TrigEvent = te
  35. UIS.TrigEvent = te
  36.  
  37. Event.OnServerEvent:Connect(function(plr,io)
  38. if plr~=Player then return end
  39. if io.isMouse then
  40. m.Target = io.Target
  41. m.Hit = io.Hit
  42. else
  43. local b = io.UserInputState == Enum.UserInputState.Begin
  44. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  45. return m:TrigEvent(b and "Button1Down" or "Button1Up")
  46. end
  47. for _,t in pairs(CAS.Actions) do
  48. for _,k in pairs(t.Keys) do
  49. if k==io.KeyCode then
  50. t.Function(t.Name,io.UserInputState,io)
  51. end
  52. end
  53. end
  54. m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  55. UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  56. end
  57. end)
  58. Event.Parent = NLS([==[
  59. local Player = game:GetService("Players")Red_Jack142
  60. local Event = script:WaitForChild("UserInput_Event")
  61.  
  62. local UIS = game:GetService("UserInputService")
  63. local input = function(io,a)
  64. if a then return end
  65. --Since InputObject is a client-side instance, we create and pass table instead
  66. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  67. end
  68. UIS.InputBegan:Connect(input)
  69. UIS.InputEnded:Connect(input)
  70.  
  71. local Mouse = Player:GetMouse()
  72. local h,t
  73. --Give the server mouse data 30 times every second, but only if the values changed
  74. --If player is not moving their mouse, client won't fire events
  75. while wait(1/30) do
  76. if h~=Mouse.Hit or t~=Mouse.Target then
  77. h,t=Mouse.Hit,Mouse.Target
  78. Event:FireServer({isMouse=true,Target=t,Hit=h})
  79. end
  80. end]==],Player.Character)
  81. Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  82. end
  83.  
  84. local Player = game:GetService("Players").Red_Jack142 --<=== Replace With Your Name
  85.  
  86.  
  87. local Mouse,mouse,UserInputService,ContextActionService
  88. do
  89. script.Parent = Player.Character
  90. local CAS = {Actions={}}
  91. local Event = Instance.new("RemoteEvent")
  92. Event.Name = "UserInput_Event"
  93. Event.Parent = Player.Character
  94. local fakeEvent = function()
  95. local t = {_fakeEvent=true}
  96. t.Connect = function(self,f)self.Function=f end
  97. t.connect = t.Connect
  98. return t
  99. end
  100. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  101. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  102. function CAS:BindAction(name,fun,touch,...)
  103. CAS.Actions[name] = {Name=name,Function=fun,Keys={...}}
  104. end
  105. function CAS:UnbindAction(name)
  106. CAS.Actions[name] = nil
  107. end
  108. local function te(self,ev,...)
  109. local t = m[ev]
  110. if t and t._fakeEvent and t.Function then
  111. t.Function(...)
  112. end
  113. end
  114. m.TrigEvent = te
  115. UIS.TrigEvent = te
  116. Event.OnServerEvent:Connect(function(plr,io)
  117. if plr~=Player then return end
  118. if io.isMouse then
  119. m.Target = io.Target
  120. m.Hit = io.Hit
  121. elseif io.UserInputType == Enum.UserInputType.MouseButton1 then
  122. if io.UserInputState == Enum.UserInputState.Begin then
  123. m:TrigEvent("Button1Down")
  124. else
  125. m:TrigEvent("Button1Up")
  126. end
  127. else
  128. for n,t in pairs(CAS.Actions) do
  129. for _,k in pairs(t.Keys) do
  130. if k==io.KeyCode then
  131. t.Function(t.Name,io.UserInputState,io)
  132. end
  133. end
  134. end
  135. if io.UserInputState == Enum.UserInputState.Begin then
  136. m:TrigEvent("KeyDown",io.KeyCode.Name:lower())
  137. UIS:TrigEvent("InputBegan",io,false)
  138. else
  139. m:TrigEvent("KeyUp",io.KeyCode.Name:lower())
  140. UIS:TrigEvent("InputEnded",io,false)
  141. end
  142. end
  143. end)
  144. Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  145. end
  146.  
  147. ---------Replace All "LocalPlayer" With Your Name.
  148. --Remove "Mouse =" or "local mouse =" at the start.
  149. --Replace Red_Jack142 At The Top Of The Script With You Name.
  150. -----------------------------Script In The Line's.
  151.  
  152.  
  153. -------------------------------------------------
Add Comment
Please, Sign In to add comment