Advertisement
plytalent

REMOTE KEY

Apr 5th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. local Player = game:GetService("Players")[script.Parent.Name] --<=== Replace With Your Name
  2.  
  3.  
  4.  
  5. local Mouse,mouse,UserInputService,ContextActionService
  6. do
  7.     script.Parent = Player.Character
  8.     local CAS = {Actions={}}
  9.     local Event = Instance.new("RemoteEvent")
  10.     Event.Name = "UserInput_Event"
  11.     Event.Parent = Player.Character
  12.     local fakeEvent = function()
  13.         local t = {_fakeEvent=true}
  14.         t.Connect = function(self,f)self.Function=f end
  15.         t.connect = t.Connect
  16.         return t
  17.     end
  18.     local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  19.     local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  20.     function CAS:BindAction(name,fun,touch,...)
  21.         CAS.Actions[name] = {Name=name,Function=fun,Keys={...}}
  22.     end
  23.     function CAS:UnbindAction(name)
  24.         CAS.Actions[name] = nil
  25.     end
  26.     local function te(self,ev,...)
  27.         local t = m[ev]
  28.         if t and t._fakeEvent and t.Function then
  29.             t.Function(...)
  30.         end
  31.     end
  32.     m.TrigEvent = te
  33.     UIS.TrigEvent = te
  34.     Event.OnServerEvent:Connect(function(plr,io)
  35.         if plr~=Player then return end
  36.         if io.isMouse then
  37.             m.Target = io.Target
  38.             m.Hit = io.Hit
  39.         elseif io.UserInputType == Enum.UserInputType.MouseButton1 then
  40.             if io.UserInputState == Enum.UserInputState.Begin then
  41.                 m:TrigEvent("Button1Down")
  42.             else
  43.                 m:TrigEvent("Button1Up")
  44.             end
  45.         else
  46.             for n,t in pairs(CAS.Actions) do
  47.                 for _,k in pairs(t.Keys) do
  48.                     if k==io.KeyCode then
  49.                         t.Function(t.Name,io.UserInputState,io)
  50.                     end
  51.                 end
  52.             end
  53.             if io.UserInputState == Enum.UserInputState.Begin then
  54.                 m:TrigEvent("KeyDown",io.KeyCode.Name:lower())
  55.                 UIS:TrigEvent("InputBegan",io,false)
  56.             else
  57.                 m:TrigEvent("KeyUp",io.KeyCode.Name:lower())
  58.                 UIS:TrigEvent("InputEnded",io,false)
  59.             end
  60.         end
  61.     end)
  62.     Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  63. end
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. local Player = game:GetService("Players").LocalPlayer
  71.  
  72.     local Char = Player.Character
  73.     local Event = Char:WaitForChild("UserInput_Event")
  74.  
  75.     local UIS = game:GetService("UserInputService")
  76.  
  77.     local input = function(io,a)
  78.         if a then return end
  79.         local io = {KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState}
  80.         Event:FireServer(io)
  81.     end
  82.     UIS.InputBegan:Connect(input)
  83.     UIS.InputEnded:Connect(input)
  84.     local Changed = false
  85.     local Mouse = Player:GetMouse()
  86.     local h,t = Mouse.Hit,Mouse.Target
  87.     while wait(1/30) do
  88.         if h~=Mouse.Hit or t~=Mouse.Target then
  89.             Event:FireServer({isMouse=true,Target=Mouse.Target,Hit=Mouse.Hit})
  90.             h,t=Mouse.Hit,Mouse.Target
  91.         end
  92.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement