plytalent

PlayerMouseModule

Dec 17th, 2020 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. local module={}
  2. local localscript = script.LocalScript:Clone()
  3. script.LocalScript:Destroy()
  4. self={}
  5. function module:GetMouse(player)
  6.     if game:GetService("RunService"):IsServer() then
  7.         if not self["Player"] then
  8.             local mouse = {}
  9.             self["Player"] = player
  10.             script.Parent = self["Player"].PlayerGui
  11.             localscript:Clone().Parent = script
  12.             local KeyDownRemote = Instance.new("RemoteEvent",script)
  13.             local KeyUpRemote = Instance.new("RemoteEvent",script)
  14.             local Button1DownRemote = Instance.new("RemoteEvent",script)
  15.             local Button1UpRemote = Instance.new("RemoteEvent",script)
  16.             local MoveRemote = Instance.new("RemoteEvent",script)
  17.             local HitRemote = Instance.new("RemoteEvent",script)
  18.             local TargetRemote = Instance.new("RemoteEvent",script)
  19.            
  20.             local KeyDownEvent = Instance.new("BindableEvent")
  21.             local KeyUpEvent = Instance.new("BindableEvent")
  22.             local Button1DownEvent = Instance.new("BindableEvent")
  23.             local Button1UpEvent = Instance.new("BindableEvent")
  24.             local MoveEvent = Instance.new("BindableEvent")
  25.            
  26.             mouse.KeyDown = KeyDownEvent.Event
  27.             mouse.KeyUp = KeyUpEvent.Event
  28.             mouse.Button1Down = Button1DownEvent.Event
  29.             mouse.Button1Up = Button1UpEvent.Event
  30.             mouse.Move = MoveEvent.Event
  31.             mouse.Target = nil
  32.             mouse.Hit = CFrame.new(0,0,0) *CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
  33.            
  34.             KeyDownRemote.OnServerEvent:Connect(function(p,k)if p == self["Player"] and k then KeyDownEvent:Fire(k) end end)
  35.             KeyUpRemote.OnServerEvent:Connect(function(p,k)if p == self["Player"] and k then KeyUpEvent:Fire(k)end end)
  36.             Button1DownRemote.OnServerEvent:Connect(function(p)if p == self["Player"] then Button1DownEvent:Fire()end end)
  37.             Button1UpRemote.OnServerEvent:Connect(function(p)if p == self["Player"] then Button1UpEvent:Fire()end end)
  38.             TargetRemote.OnServerEvent:Connect(function(p,t)if p == self["Player"] then mouse.Target=t end end)
  39.             HitRemote.OnServerEvent:Connect(function(p,h)if p == self["Player"]then mouse.Hit = h end end)
  40.            
  41.             KeyDownRemote.Name = "KeyDown"
  42.             KeyUpRemote.Name = "KeyUp"
  43.             Button1DownRemote.Name = "Button1Down"
  44.             Button1UpRemote.Name = "Button1Up"
  45.             MoveRemote.Name = "Move"
  46.             HitRemote.Name = "Hit"
  47.             TargetRemote.Name = "Target"
  48.             return mouse
  49.         end
  50.     else
  51.         error("THIS IS SERVER SIDE SCRIPT")
  52.     end
  53. end
  54. return module
Add Comment
Please, Sign In to add comment