Advertisement
InTesting

VSB for Seat

Dec 31st, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. -- BTools in VSB won't make a functioning seat so here you go.
  2.  
  3.  
  4. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  5. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  6. do
  7.     print("FE Compatibility code by Mokiros | Translated to FE by iPxter")
  8.     script.Parent = Player.Character
  9.  
  10.     --RemoteEvent for communicating
  11.     local Event = Instance.new("RemoteEvent")
  12.     Event.Name = "UserInput_Event"
  13.     --Fake event to make stuff like Mouse.KeyDown work
  14.     local function fakeEvent()
  15.         local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
  16.         t.connect = t.Connect
  17.         return t
  18.     end
  19.     --Creating fake input objects with fake variables
  20.     local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  21.     local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  22.     local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  23.         CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  24.     end}
  25.     --Merged 2 functions into one by checking amount of arguments
  26.     CAS.UnbindAction = CAS.BindAction
  27.  
  28.     --This function will trigger the events that have been :Connect()'ed
  29.     local function te(self,ev,...)
  30.         local t = m[ev]
  31.         if t and t._fakeEvent and t.Function then
  32.             t.Function(...)
  33.         end
  34.     end
  35.     m.TrigEvent = te
  36.     UIS.TrigEvent = te
  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").LocalPlayer
  60.     local Event = script:WaitForChild("UserInput_Event")
  61.     local UIS = game:GetService("UserInputService")
  62.     local input = function(io,a)
  63.         if a then return end
  64.         --Since InputObject is a client-side instance, we create and pass table instead
  65.         Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  66.     end
  67.     UIS.InputBegan:Connect(input)
  68.     UIS.InputEnded:Connect(input)
  69.     local Mouse = Player:GetMouse()
  70.     local h,t
  71.     --Give the server mouse data 30 times every second, but only if the values changed
  72.     --If player is not moving their mouse, client won't fire events
  73.     while wait(1/30) do
  74.         if h~=Mouse.Hit or t~=Mouse.Target then
  75.             h,t=Mouse.Hit,Mouse.Target
  76.             Event:FireServer({isMouse=true,Target=t,Hit=h})
  77.         end
  78.     end]==],Player.Character)
  79.     Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  80. end
  81. -- End of FE converter
  82.  
  83.     local S = Instance.new("Seat",game.Workspace)
  84.     S.Name = "FESeat"
  85.     S.Material = Enum.Material.Neon
  86.     S.Position = owner.Character.Head.Position
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement