Advertisement
InTesting

E to teleport

Jan 1st, 2019
2,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. -- mainly testing keybinds and mouse.hit
  2. print'https://pastebin.com/jcF5UxGs'
  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,Mouse,mouse,UserInputService,ContextActionService = owner
  5. do
  6.     print("FE Compatibility code by Mokiros | Translated to FE by iPxter")
  7.     script.Parent = Player.Character
  8.  
  9.     --RemoteEvent for communicating
  10.     local Event = Instance.new("RemoteEvent")
  11.     Event.Name = "UserInput_Event"
  12.     --Fake event to make stuff like Mouse.KeyDown work
  13.     local function fakeEvent()
  14.         local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
  15.         t.connect = t.Connect
  16.         return t
  17.     end
  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.     Event.OnServerEvent:Connect(function(plr,io)
  37.         if plr~=Player then return end
  38.         if io.isMouse then
  39.             m.Target = io.Target
  40.             m.Hit = io.Hit
  41.         else
  42.             local b = io.UserInputState == Enum.UserInputState.Begin
  43.             if io.UserInputType == Enum.UserInputType.MouseButton1 then
  44.                 return m:TrigEvent(b and "Button1Down" or "Button1Up")
  45.             end
  46.             for _,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.             m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  54.             UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  55.         end
  56.     end)
  57.     Event.Parent = NLS([==[
  58.     local Player = game:GetService("Players").LocalPlayer
  59.     local Event = script:WaitForChild("UserInput_Event")
  60.     local UIS = game:GetService("UserInputService")
  61.     local input = function(io,a)
  62.         if a then return end
  63.         --Since InputObject is a client-side instance, we create and pass table instead
  64.         Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  65.     end
  66.     UIS.InputBegan:Connect(input)
  67.     UIS.InputEnded:Connect(input)
  68.     local Mouse = Player:GetMouse()
  69.     local h,t
  70.     --Give the server mouse data 30 times every second, but only if the values changed
  71.     --If player is not moving their mouse, client won't fire events
  72.     while wait(1/30) do
  73.         if h~=Mouse.Hit or t~=Mouse.Target then
  74.             h,t=Mouse.Hit,Mouse.Target
  75.             Event:FireServer({isMouse=true,Target=t,Hit=h})
  76.         end
  77.     end]==],Player.Character)
  78.     Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  79. end
  80. -- End of FE converter
  81. local player = owner
  82. local char = owner.Character
  83. if char and player then
  84.     mouse.KeyDown:Connect(function(key)
  85.         if key=="e" then
  86.             if mouse.Target==nil then
  87.                 print("Ignored teleporting to skybox.")
  88.             else
  89.                 char.HumanoidRootPart.CFrame = mouse.Hit -- Hit is a CFrame and character faces the mouse
  90.             end
  91.         end
  92.     end)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement