View difference between Paste ID: 8KyQNF63 and xjQN8McE
SHOW: | | - or go back to the newest paste.
1-
--just put this on the top of a script and boom 89% works
1+
2-
--note this does not work on big scripts
2+
3-
if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
3+
4-
local Player,game,owner = owner,game
4+
5-
local RealPlayer = Player
5+
6-
do
6+
7-
    local rp = RealPlayer
7+
8-
    script.Parent = rp.Character
8+
9-
   
9+
10-
    --RemoteEvent for communicating
10+
11-
    local Event = Instance.new("RemoteEvent")
11+
12-
    Event.Name = "UserInput_Event"
12+
13-
 
13+
14-
    --Fake event to make stuff like Mouse.KeyDown work
14+
15-
    local function fakeEvent()
15+
16-
        local t = {_fakeEvent=true,Functions={},Connect=function(self,f)table.insert(self.Functions,f) end}
16+
17-
        t.connect = t.Connect
17+
18-
        return t
18+
19-
    end
19+
20-
 
20+
21-
    --Creating fake input objects with fake variables
21+
22-
    local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
22+
23-
    local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
23+
24-
    local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
24+
25-
        CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
25+
26-
    end}
26+
27-
    --Merged 2 functions into one by checking amount of arguments
27+
28-
    CAS.UnbindAction = CAS.BindAction
28+
29-
 
29+
30-
    --This function will trigger the events that have been :Connect()'ed
30+
31-
    local function te(self,ev,...)
31+
32-
        local t = m[ev]
32+
33-
        if t and t._fakeEvent then
33+
34-
            for _,f in pairs(t.Functions) do
34+
35-
                f(...)
35+
36-
            end
36+
37-
        end
37+
38-
    end
38+
39-
    m.TrigEvent = te
39+
40-
    UIS.TrigEvent = te
40+
41-
 
41+
42-
    Event.OnServerEvent:Connect(function(plr,io)
42+
43-
        if plr~=rp then return end
43+
44-
        m.Target = io.Target
44+
45-
        m.Hit = io.Hit
45+
46-
        if not io.isMouse then
46+
47-
            local b = io.UserInputState == Enum.UserInputState.Begin
47+
48-
            if io.UserInputType == Enum.UserInputType.MouseButton1 then
48+
49-
                return m:TrigEvent(b and "Button1Down" or "Button1Up")
49+
50-
            end
50+
51-
            for _,t in pairs(CAS.Actions) do
51+
52-
                for _,k in pairs(t.Keys) do
52+
53-
                    if k==io.KeyCode then
53+
54-
                        t.Function(t.Name,io.UserInputState,io)
54+
55-
                    end
55+
56-
                end
56+
57-
            end
57+
58-
            m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
58+
59-
            UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
59+
60-
        end
60+
61-
    end)
61+
62-
    Event.Parent = NLS([==[
62+
63-
    local Player = game:GetService("Players").LocalPlayer
63+
64-
    local Event = script:WaitForChild("UserInput_Event")
64+
65-
 
65+
66-
    local Mouse = Player:GetMouse()
66+
67-
    local UIS = game:GetService("UserInputService")
67+
68-
    local input = function(io,a)
68+
69-
        if a then return end
69+
70-
        --Since InputObject is a client-side instance, we create and pass table instead
70+
71-
        Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
71+
72-
    end
72+
73-
    UIS.InputBegan:Connect(input)
73+
74-
    UIS.InputEnded:Connect(input)
74+
75-
 
75+
76-
    local h,t
76+
77-
    --Give the server mouse data 30 times every second, but only if the values changed
77+
78-
    --If player is not moving their mouse, client won't fire events
78+
79-
    while wait(1/30) do
79+
80-
        if h~=Mouse.Hit or t~=Mouse.Target then
80+
81-
            h,t=Mouse.Hit,Mouse.Target
81+
82-
            Event:FireServer({isMouse=true,Target=t,Hit=h})
82+
83-
        end
83+
84-
    end]==],Player.Character)
84+
85-
 
85+
86-
    ----Sandboxed game object that allows the usage of client-side methods and services
86+
87-
    --Real game object
87+
88-
    local _rg = game
88+
89-
 
89+
90-
    --Metatable for fake service
90+
91-
    local fsmt = {
91+
92-
        __index = function(self,k)
92+
93-
            local s = rawget(self,"_RealService")
93+
94-
            if s then return s[k] end
94+
95-
        end,
95+
96-
        __newindex = function(self,k,v)
96+
97-
            local s = rawget(self,"_RealService")
97+
98-
            if s then s[k]=v end
98+
99-
        end,
99+
100-
        __call = function(self,...)
100+
101-
            local s = rawget(self,"_RealService")
101+
102-
            if s then return s(...) end
102+
103-
        end
103+
104-
    }
104+
105-
    local function FakeService(t,RealService)
105+
106-
        t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
106+
107-
        return setmetatable(t,fsmt)
107+
108-
    end
108+
109-
 
109+
110-
    --Fake game object
110+
111-
    local g = {
111+
112-
        GetService = function(self,s)
112+
113-
            return self[s]
113+
114-
        end,
114+
115-
        Players = FakeService({
115+
116-
            LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
116+
117-
        },"Players"),
117+
118-
        UserInputService = FakeService(UIS,"UserInputService"),
118+
119-
        ContextActionService = FakeService(CAS,"ContextActionService"),
119+
120-
    }
120+
121-
    rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
121+
122-
    g.service = g.GetService
122+
123-
   
123+