SHOW:
|
|
- or go back to the newest paste.
| 1 | https://github.com/Mokiros/roblox-FE-compatibility | |
| 2 | if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
| |
| 3 | local Player,game,owner = owner,game | |
| 4 | local RealPlayer = Player | |
| 5 | do | |
| 6 | print("FE Compatibility code V2 by Mokiros")
| |
| 7 | local RealPlayer = RealPlayer | |
| 8 | script.Parent = RealPlayer.Character | |
| 9 | ||
| 10 | --Fake event to make stuff like Mouse.KeyDown work | |
| 11 | local Disconnect_Function = function(this) | |
| 12 | this[1].Functions[this[2]] = nil | |
| 13 | end | |
| 14 | local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
| |
| 15 | local FakeEvent_Metatable = {__index={
| |
| 16 | Connect = function(this,f) | |
| 17 | local i = tostring(math.random(0,10000)) | |
| 18 | while this.Functions[i] do | |
| 19 | i = tostring(math.random(0,10000)) | |
| 20 | end | |
| 21 | this.Functions[i] = f | |
| 22 | return setmetatable({this,i},Disconnect_Metatable)
| |
| 23 | end | |
| 24 | }} | |
| 25 | FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect | |
| 26 | local function fakeEvent() | |
| 27 | return setmetatable({Functions={}},FakeEvent_Metatable)
| |
| 28 | end | |
| 29 | ||
| 30 | --Creating fake input objects with fake variables | |
| 31 | local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
| |
| 32 | FakeMouse.keyUp = FakeMouse.KeyUp | |
| 33 | FakeMouse.keyDown = FakeMouse.KeyDown | |
| 34 | local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
| |
| 35 | local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
| |
| 36 | CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
| |
| 37 | end} | |
| 38 | --Merged 2 functions into one by checking amount of arguments | |
| 39 | CAS.UnbindAction = CAS.BindAction | |
| 40 | ||
| 41 | --This function will trigger the events that have been :Connect()'ed | |
| 42 | local function TriggerEvent(self,ev,...) | |
| 43 | for _,f in pairs(self[ev].Functions) do | |
| 44 | f(...) | |
| 45 | end | |
| 46 | end | |
| 47 | FakeMouse.TriggerEvent = TriggerEvent | |
| 48 | UIS.TriggerEvent = TriggerEvent | |
| 49 | ||
| 50 | --Client communication | |
| 51 | local Event = Instance.new("RemoteEvent")
| |
| 52 | Event.Name = "UserInput_Event" | |
| 53 | Event.OnServerEvent:Connect(function(plr,io) | |
| 54 | if plr~=RealPlayer then return end | |
| 55 | FakeMouse.Target = io.Target | |
| 56 | FakeMouse.Hit = io.Hit | |
| 57 | if not io.isMouse then | |
| 58 | local b = io.UserInputState == Enum.UserInputState.Begin | |
| 59 | if io.UserInputType == Enum.UserInputType.MouseButton1 then | |
| 60 | return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up") | |
| 61 | end | |
| 62 | if io.UserInputType == Enum.UserInputType.MouseButton2 then | |
| 63 | return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up") | |
| 64 | end | |
| 65 | for _,t in pairs(CAS.Actions) do | |
| 66 | for _,k in pairs(t.Keys) do | |
| 67 | if k==io.KeyCode then | |
| 68 | t.Function(t.Name,io.UserInputState,io) | |
| 69 | end | |
| 70 | end | |
| 71 | end | |
| 72 | FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower()) | |
| 73 | UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false) | |
| 74 | end | |
| 75 | end) | |
| 76 | Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
| |
| 77 | local Mouse = owner:GetMouse() | |
| 78 | local UIS = game:GetService("UserInputService")
| |
| 79 | local input = function(io,RobloxHandled) | |
| 80 | if RobloxHandled then return end | |
| 81 | --Since InputObject is a client-side instance, we create and pass table instead | |
| 82 | Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
| |
| 83 | end | |
| 84 | UIS.InputBegan:Connect(input) | |
| 85 | UIS.InputEnded:Connect(input) | |
| 86 | ||
| 87 | local h,t | |
| 88 | --Give the server mouse data every second frame, but only if the values changed | |
| 89 | --If player is not moving their mouse, client won't fire events | |
| 90 | local HB = game:GetService("RunService").Heartbeat
| |
| 91 | while true do | |
| 92 | if h~=Mouse.Hit or t~=Mouse.Target then | |
| 93 | h,t=Mouse.Hit,Mouse.Target | |
| 94 | Event:FireServer({isMouse=true,Target=t,Hit=h})
| |
| 95 | end | |
| 96 | --Wait 2 frames | |
| 97 | for i=1,2 do | |
| 98 | HB:Wait() | |
| 99 | end | |
| 100 | end]==],script) | |
| 101 | ||
| 102 | ----Sandboxed game object that allows the usage of client-side methods and services | |
| 103 | --Real game object | |
| 104 | local RealGame = game | |
| 105 | ||
| 106 | --Metatable for fake service | |
| 107 | local FakeService_Metatable = {
| |
| 108 | __index = function(self,k) | |
| 109 | local s = rawget(self,"_RealService") | |
| 110 | if s then | |
| 111 | return typeof(s[k])=="function" | |
| 112 | and function(_,...)return s[k](s,...)end or s[k] | |
| 113 | end | |
| 114 | end, | |
| 115 | __newindex = function(self,k,v) | |
| 116 | local s = rawget(self,"_RealService") | |
| 117 | if s then s[k]=v end | |
| 118 | end | |
| 119 | } | |
| 120 | local function FakeService(t,RealService) | |
| 121 | t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService | |
| 122 | return setmetatable(t,FakeService_Metatable) | |
| 123 | end | |
| 124 | ||
| 125 | --Fake game object | |
| 126 | local FakeGame = {
| |
| 127 | GetService = function(self,s) | |
| 128 | return rawget(self,s) or RealGame:GetService(s) | |
| 129 | end, | |
| 130 | Players = FakeService({
| |
| 131 | LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
| |
| 132 | },"Players"), | |
| 133 | UserInputService = FakeService(UIS,"UserInputService"), | |
| 134 | ContextActionService = FakeService(CAS,"ContextActionService"), | |
| 135 | RunService = FakeService({
| |
| 136 | _btrs = {},
| |
| 137 | RenderStepped = RealGame:GetService("RunService").Heartbeat,
| |
| 138 | BindToRenderStep = function(self,name,_,fun) | |
| 139 | self._btrs[name] = self.Heartbeat:Connect(fun) | |
| 140 | end, | |
| 141 | UnbindFromRenderStep = function(self,name) | |
| 142 | self._btrs[name]:Disconnect() | |
| 143 | end, | |
| 144 | },"RunService") | |
| 145 | } | |
| 146 | rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer) | |
| 147 | FakeGame.service = FakeGame.GetService | |
| 148 | FakeService(FakeGame,https://github.com/Mokiros/roblox-FE-compatibility | |
| 149 | if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
| |
| 150 | local Player,game,owner = owner,game | |
| 151 | local RealPlayer = Player | |
| 152 | do | |
| 153 | print("FE Compatibility code V2 by Mokiros")
| |
| 154 | local RealPlayer = RealPlayer | |
| 155 | script.Parent = RealPlayer.Character | |
| 156 | ||
| 157 | --Fake event to make stuff like Mouse.KeyDown work | |
| 158 | local Disconnect_Function = function(this) | |
| 159 | this[1].Functions[this[2]] = nil | |
| 160 | end | |
| 161 | local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
| |
| 162 | local FakeEvent_Metatable = {__index={
| |
| 163 | Connect = function(this,f) | |
| 164 | local i = tostring(math.random(0,10000)) | |
| 165 | while this.Functions[i] do | |
| 166 | i = tostring(math.random(0,10000)) | |
| 167 | end | |
| 168 | this.Functions[i] = f | |
| 169 | return setmetatable({this,i},Disconnect_Metatable)
| |
| 170 | end | |
| 171 | }} | |
| 172 | FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect | |
| 173 | local function fakeEvent() | |
| 174 | return setmetatable({Functions={}},FakeEvent_Metatable)
| |
| 175 | end | |
| 176 | ||
| 177 | --Creating fake input objects with fake variables | |
| 178 | local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
| |
| 179 | FakeMouse.keyUp = FakeMouse.KeyUp | |
| 180 | FakeMouse.keyDown = FakeMouse.KeyDown | |
| 181 | local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
| |
| 182 | local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
| |
| 183 | CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
| |
| 184 | end} | |
| 185 | --Merged 2 functions into one by checking amount of arguments | |
| 186 | CAS.UnbindAction = CAS.BindAction | |
| 187 | ||
| 188 | --This function will trigger the events that have been :Connect()'ed | |
| 189 | local function TriggerEvent(self,ev,...) | |
| 190 | for _,f in pairs(self[ev].Functions) do | |
| 191 | f(...) | |
| 192 | end | |
| 193 | end | |
| 194 | FakeMouse.TriggerEvent = TriggerEvent | |
| 195 | UIS.TriggerEvent = TriggerEvent | |
| 196 | ||
| 197 | --Client communication | |
| 198 | local Event = Instance.new("RemoteEvent")
| |
| 199 | Event.Name = "UserInput_Event" | |
| 200 | Event.OnServerEvent:Connect(function(plr,io) | |
| 201 | if plr~=RealPlayer then return end | |
| 202 | FakeMouse.Target = io.Target | |
| 203 | FakeMouse.Hit = io.Hit | |
| 204 | if not io.isMouse then | |
| 205 | local b = io.UserInputState == Enum.UserInputState.Begin | |
| 206 | if io.UserInputType == Enum.UserInputType.MouseButton1 then | |
| 207 | return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up") | |
| 208 | end | |
| 209 | if io.UserInputType == Enum.UserInputType.MouseButton2 then | |
| 210 | return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up") | |
| 211 | end | |
| 212 | for _,t in pairs(CAS.Actions) do | |
| 213 | for _,k in pairs(t.Keys) do | |
| 214 | if k==io.KeyCode then | |
| 215 | t.Function(t.Name,io.UserInputState,io) | |
| 216 | end | |
| 217 | end | |
| 218 | end | |
| 219 | FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower()) | |
| 220 | UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false) | |
| 221 | end | |
| 222 | end) | |
| 223 | Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
| |
| 224 | local Mouse = owner:GetMouse() | |
| 225 | local UIS = game:GetService("UserInputService")
| |
| 226 | local input = function(io,RobloxHandled) | |
| 227 | if RobloxHandled then return end | |
| 228 | --Since InputObject is a client-side instance, we create and pass table instead | |
| 229 | Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
| |
| 230 | end | |
| 231 | UIS.InputBegan:Connect(input) | |
| 232 | UIS.InputEnded:Connect(input) | |
| 233 | ||
| 234 | local h,t | |
| 235 | --Give the server mouse data every second frame, but only if the values changed | |
| 236 | --If player is not moving their mouse, client won't fire events | |
| 237 | local HB = game:GetService("RunService").Heartbeat
| |
| 238 | while true do | |
| 239 | if h~=Mouse.Hit or t~=Mouse.Target then | |
| 240 | h,t=Mouse.Hit,Mouse.Target | |
| 241 | Event:FireServer({isMouse=true,Target=t,Hit=h})
| |
| 242 | end | |
| 243 | --Wait 2 frames | |
| 244 | for i=1,2 do | |
| 245 | HB:Wait() | |
| 246 | end | |
| 247 | end]==],script) | |
| 248 | ||
| 249 | ----Sandboxed game object that allows the usage of client-side methods and services | |
| 250 | --Real game object | |
| 251 | local RealGame = game | |
| 252 | ||
| 253 | --Metatable for fake service | |
| 254 | local FakeService_Metatable = {
| |
| 255 | __index = function(self,k) | |
| 256 | local s = rawget(self,"_RealService") | |
| 257 | if s then | |
| 258 | return typeof(s[k])=="function" | |
| 259 | and function(_,...)return s[k](s,...)end or s[k] | |
| 260 | end | |
| 261 | end, | |
| 262 | __newindex = function(self,k,v) | |
| 263 | local s = rawget(self,"_RealService") | |
| 264 | if s then s[k]=v end | |
| 265 | end | |
| 266 | } | |
| 267 | local function FakeService(t,RealService) | |
| 268 | t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService | |
| 269 | return setmetatable(t,FakeService_Metatable) | |
| 270 | end | |
| 271 | ||
| 272 | --Fake game object | |
| 273 | local FakeGame = {
| |
| 274 | GetService = function(self,s) | |
| 275 | return rawget(self,s) or RealGame:GetService(s) | |
| 276 | end, | |
| 277 | Players = FakeService({
| |
| 278 | LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
| |
| 279 | },"Players"), | |
| 280 | UserInputService = FakeService(UIS,"UserInputService"), | |
| 281 | ContextActionService = FakeService(CAS,"ContextActionService"), | |
| 282 | RunService = FakeService({
| |
| 283 | _btrs = {},
| |
| 284 | RenderStepped = RealGame:GetService("RunService").Heartbeat,
| |
| 285 | BindToRenderStep = function(self,name,_,fun) | |
| 286 | self._btrs[name] = self.Heartbeat:Connect(fun) | |
| 287 | end, | |
| 288 | UnbindFromRenderStep = function(self,name) | |
| 289 | self._btrs[name]:Disconnect() | |
| 290 | end, | |
| 291 | },"RunService") | |
| 292 | } | |
| 293 | rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer) | |
| 294 | FakeGame.service = FakeGame.GetService | |
| 295 | FakeService(FakeGame,game) | |
| 296 | --Changing owner to fake player object to support owner:GetMouse() | |
| 297 | game,owner = FakeGame,FakeGame.Players.LocalPlayer | |
| 298 | end) | |
| 299 | --Changing owner to fake player object to support owner:GetMouse() | |
| 300 | game,owner = FakeGame,FakeGame.Players.LocalPlayer | |
| 301 | end | |
| 302 | ||
| 303 | --------------------------- | |
| 304 | --Created by DJwaffle2005-- | |
| 305 | --------------------------- | |
| 306 | wait(0.1) | |
| 307 | ||
| 308 | player = game.Players.iiSalsaJay | |
| 309 | workspacePlayer = game.Workspace.iiSalsaJay | |
| 310 | ||
| 311 | local ff = Instance.new("ForceField") --Creates forcefield
| |
| 312 | ff.Parent = workspacePlayer | |
| 313 | ||
| 314 | workspacePlayer.Humanoid.WalkSpeed = 30 | |
| 315 | ||
| 316 | local tool1 = Instance.new("HopperBin") --Gives the player a grab tool.
| |
| 317 | tool1.Name = "Grab" | |
| 318 | tool1.Parent = player.Backpack | |
| 319 | tool1.BinType = "Grab" | |
| 320 | print("Gave grab tool")
| |
| 321 | ||
| 322 | local tool2 = Instance.new("HopperBin") --Gives the player a clone tool.
| |
| 323 | tool2.Name = "Clone" | |
| 324 | tool2.Parent = player.Backpack | |
| 325 | tool2.BinType = "Clone" | |
| 326 | print("Gave clone tool")
| |
| 327 | ||
| 328 | local tool3 = Instance.new("HopperBin") --Gives the player a destroy tool.
| |
| 329 | tool3.Name = "Hammer" | |
| 330 | tool3.Parent = player.Backpack | |
| 331 | tool3.BinType = "Hammer" | |
| 332 | print("Gave delete tool")
| |
| 333 | ||
| 334 | local tool4 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 335 | tool4.Name = "New Part" | |
| 336 | tool4.Parent = player.Backpack | |
| 337 | tool4.BinType = "Script" | |
| 338 | print("Gave new part tool")
| |
| 339 | ||
| 340 | local tool5 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 341 | tool5.Name = "Paint" | |
| 342 | tool5.Parent = player.Backpack | |
| 343 | tool5.BinType = "Script" | |
| 344 | print("Gave paint tool")
| |
| 345 | ||
| 346 | local tool6 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 347 | tool6.Name = "Anchor" | |
| 348 | tool6.Parent = player.Backpack | |
| 349 | tool6.BinType = "Script" | |
| 350 | print("Gave anchor tool")
| |
| 351 | ||
| 352 | local tool7 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 353 | tool7.Name = "Un-Anchor" | |
| 354 | tool7.Parent = player.Backpack | |
| 355 | tool7.BinType = "Script" | |
| 356 | print("Gave un-anchor tool")
| |
| 357 | ||
| 358 | local tool8 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 359 | tool8.Name = "Lock" | |
| 360 | tool8.Parent = player.Backpack | |
| 361 | tool8.BinType = "Script" | |
| 362 | print("Gave lock tool")
| |
| 363 | ||
| 364 | local tool9 = Instance.new("HopperBin") --Gives the player a tool where it spawns a part.
| |
| 365 | tool9.Name = "Unlock" | |
| 366 | tool9.Parent = player.Backpack | |
| 367 | tool9.BinType = "Script" | |
| 368 | print("Gave unlock tool")
| |
| 369 | ||
| 370 | playerMouse = game.Players.LocalPlayer:GetMouse() | |
| 371 | ||
| 372 | ||
| 373 | --Functions-- | |
| 374 | function lock() | |
| 375 | playerMouse.Target.Locked = true | |
| 376 | print("Locked "..playerMouse.Target.Name)
| |
| 377 | end | |
| 378 | ||
| 379 | function unlock() | |
| 380 | playerMouse.Target.Locked = false | |
| 381 | print("Unlocked "..playerMouse.Target.Name)
| |
| 382 | end | |
| 383 | ||
| 384 | function anchor() | |
| 385 | playerMouse.Target.Anchored = true | |
| 386 | print("Anchored "..playerMouse.Target.Name)
| |
| 387 | end | |
| 388 | ||
| 389 | function unanchor() | |
| 390 | playerMouse.Target.Anchored = false | |
| 391 | print("Un-anchored "..playerMouse.Target.Name)
| |
| 392 | end | |
| 393 | ||
| 394 | function paint() | |
| 395 | playerMouse.Target.BrickColor = BrickColor.Random() | |
| 396 | end | |
| 397 | ||
| 398 | function create(mouse) | |
| 399 | local part = Instance.new("Part")
| |
| 400 | part.Parent = game.Workspace | |
| 401 | part.Position = player.Head.Position | |
| 402 | part.Anchored = true | |
| 403 | part.Locked = false | |
| 404 | print("Created a new part.")
| |
| 405 | end | |
| 406 | ||
| 407 | ------------------------ | |
| 408 | ||
| 409 | --Events- | |
| 410 | ||
| 411 | tool4.Selected:connect(function(mouse) | |
| 412 | print("Selected.")
| |
| 413 | mouse.Button1Down:connect(create) | |
| 414 | end) | |
| 415 | ||
| 416 | tool5.Selected:connect(function(mouse) | |
| 417 | print("Selected.")
| |
| 418 | mouse.Button1Down:connect(paint) | |
| 419 | end) | |
| 420 | ||
| 421 | tool6.Selected:connect(function(mouse) | |
| 422 | print("Selected.")
| |
| 423 | mouse.Button1Down:connect(anchor) | |
| 424 | end) | |
| 425 | ||
| 426 | tool7.Selected:connect(function(mouse) | |
| 427 | print("Selected.")
| |
| 428 | mouse.Button1Down:connect(unanchor) | |
| 429 | end) | |
| 430 | ||
| 431 | tool8.Selected:connect(function(mouse) | |
| 432 | print("Selected.")
| |
| 433 | mouse.Button1Down:connect(lock) | |
| 434 | end) | |
| 435 | ||
| 436 | tool9.Selected:connect(function(mouse) | |
| 437 | print("Selected.")
| |
| 438 | mouse.Button1Down:connect(unlock) | |
| 439 | end) | |
| 440 | ||
| 441 | print("Gave tools to "..player.Name..".") |