SHOW:
|
|
- or go back to the newest paste.
| 1 | --- [[ Simple Time Rewind ]] --- | |
| 2 | -- by fo43123 | |
| 3 | ||
| 4 | --https://github.com/Mokiros/roblox-FE-compatibility | |
| 5 | if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
| |
| 6 | local Player,game,owner = owner,game | |
| 7 | local RealPlayer = Player | |
| 8 | do | |
| 9 | print("FE Compatibility code V2 by Mokiros")
| |
| 10 | local RealPlayer = RealPlayer | |
| 11 | script.Parent = RealPlayer.Character | |
| 12 | ||
| 13 | --Fake event to make stuff like Mouse.KeyDown work | |
| 14 | local Disconnect_Function = function(this) | |
| 15 | this[1].Functions[this[2]] = nil | |
| 16 | end | |
| 17 | local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
| |
| 18 | local FakeEvent_Metatable = {__index={
| |
| 19 | Connect = function(this,f) | |
| 20 | local i = tostring(math.random(0,10000)) | |
| 21 | while this.Functions[i] do | |
| 22 | i = tostring(math.random(0,10000)) | |
| 23 | end | |
| 24 | this.Functions[i] = f | |
| 25 | return setmetatable({this,i},Disconnect_Metatable)
| |
| 26 | end | |
| 27 | }} | |
| 28 | FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect | |
| 29 | local function fakeEvent() | |
| 30 | return setmetatable({Functions={}},FakeEvent_Metatable)
| |
| 31 | end | |
| 32 | ||
| 33 | --Creating fake input objects with fake variables | |
| 34 | local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
| |
| 35 | FakeMouse.keyUp = FakeMouse.KeyUp | |
| 36 | FakeMouse.keyDown = FakeMouse.KeyDown | |
| 37 | local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
| |
| 38 | local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
| |
| 39 | CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
| |
| 40 | end} | |
| 41 | --Merged 2 functions into one by checking amount of arguments | |
| 42 | CAS.UnbindAction = CAS.BindAction | |
| 43 | ||
| 44 | --This function will trigger the events that have been :Connect()'ed | |
| 45 | local function TriggerEvent(self,ev,...) | |
| 46 | for _,f in pairs(self[ev].Functions) do | |
| 47 | f(...) | |
| 48 | end | |
| 49 | end | |
| 50 | FakeMouse.TriggerEvent = TriggerEvent | |
| 51 | UIS.TriggerEvent = TriggerEvent | |
| 52 | ||
| 53 | --Client communication | |
| 54 | local Event = Instance.new("RemoteEvent")
| |
| 55 | Event.Name = "UserInput_Event" | |
| 56 | Event.OnServerEvent:Connect(function(plr,io) | |
| 57 | if plr~=RealPlayer then return end | |
| 58 | FakeMouse.Target = io.Target | |
| 59 | FakeMouse.Hit = io.Hit | |
| 60 | if not io.isMouse then | |
| 61 | local b = io.UserInputState == Enum.UserInputState.Begin | |
| 62 | if io.UserInputType == Enum.UserInputType.MouseButton1 then | |
| 63 | return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up") | |
| 64 | end | |
| 65 | if io.UserInputType == Enum.UserInputType.MouseButton2 then | |
| 66 | return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up") | |
| 67 | end | |
| 68 | for _,t in pairs(CAS.Actions) do | |
| 69 | for _,k in pairs(t.Keys) do | |
| 70 | if k==io.KeyCode then | |
| 71 | t.Function(t.Name,io.UserInputState,io) | |
| 72 | end | |
| 73 | end | |
| 74 | end | |
| 75 | FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower()) | |
| 76 | UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false) | |
| 77 | end | |
| 78 | end) | |
| 79 | Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
| |
| 80 | local Mouse = owner:GetMouse() | |
| 81 | local UIS = game:GetService("UserInputService")
| |
| 82 | local input = function(io,RobloxHandled) | |
| 83 | if RobloxHandled then return end | |
| 84 | --Since InputObject is a client-side instance, we create and pass table instead | |
| 85 | Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
| |
| 86 | end | |
| 87 | UIS.InputBegan:Connect(input) | |
| 88 | UIS.InputEnded:Connect(input) | |
| 89 | local h,t | |
| 90 | --Give the server mouse data every second frame, but only if the values changed | |
| 91 | --If player is not moving their mouse, client won't fire events | |
| 92 | local HB = game:GetService("RunService").Heartbeat
| |
| 93 | while true do | |
| 94 | if h~=Mouse.Hit or t~=Mouse.Target then | |
| 95 | h,t=Mouse.Hit,Mouse.Target | |
| 96 | Event:FireServer({isMouse=true,Target=t,Hit=h})
| |
| 97 | end | |
| 98 | --Wait 2 frames | |
| 99 | for i=1,2 do | |
| 100 | HB:Wait() | |
| 101 | end | |
| 102 | end]==],script) | |
| 103 | ||
| 104 | ----Sandboxed game object that allows the usage of client-side methods and services | |
| 105 | --Real game object | |
| 106 | local RealGame = game | |
| 107 | ||
| 108 | --Metatable for fake service | |
| 109 | local FakeService_Metatable = {
| |
| 110 | __index = function(self,k) | |
| 111 | local s = rawget(self,"_RealService") | |
| 112 | if s then | |
| 113 | return typeof(s[k])=="function" | |
| 114 | and function(_,...)return s[k](s,...)end or s[k] | |
| 115 | end | |
| 116 | end, | |
| 117 | __newindex = function(self,k,v) | |
| 118 | local s = rawget(self,"_RealService") | |
| 119 | if s then s[k]=v end | |
| 120 | end | |
| 121 | } | |
| 122 | local function FakeService(t,RealService) | |
| 123 | t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService | |
| 124 | return setmetatable(t,FakeService_Metatable) | |
| 125 | end | |
| 126 | ||
| 127 | --Fake game object | |
| 128 | local FakeGame = {
| |
| 129 | GetService = function(self,s) | |
| 130 | return rawget(self,s) or RealGame:GetService(s) | |
| 131 | end, | |
| 132 | Players = FakeService({
| |
| 133 | LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
| |
| 134 | },"Players"), | |
| 135 | UserInputService = FakeService(UIS,"UserInputService"), | |
| 136 | ContextActionService = FakeService(CAS,"ContextActionService"), | |
| 137 | RunService = FakeService({
| |
| 138 | _btrs = {},
| |
| 139 | RenderStepped = RealGame:GetService("RunService").Heartbeat,
| |
| 140 | BindToRenderStep = function(self,name,_,fun) | |
| 141 | self._btrs[name] = self.Heartbeat:Connect(fun) | |
| 142 | end, | |
| 143 | UnbindFromRenderStep = function(self,name) | |
| 144 | self._btrs[name]:Disconnect() | |
| 145 | end, | |
| 146 | },"RunService") | |
| 147 | } | |
| 148 | rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer) | |
| 149 | FakeGame.service = FakeGame.GetService | |
| 150 | FakeService(FakeGame,game) | |
| 151 | --Changing owner to fake player object to support owner:GetMouse() | |
| 152 | game,owner = FakeGame,FakeGame.Players.LocalPlayer | |
| 153 | end | |
| 154 | ||
| 155 | local me = game.Players.LocalPlayer | |
| 156 | local mouse = me:GetMouse() | |
| 157 | local char = me.Character | |
| 158 | local hum = char:FindFirstChild('Humanoid')
| |
| 159 | local hd = char:FindFirstChild('Head')
| |
| 160 | local ts = char:FindFirstChild('Torso') or char:FindFirstChild('UpperTorso')
| |
| 161 | local ra = char:FindFirstChild('Right Arm') or char:FindFirstChild('RightUpperArm')
| |
| 162 | local la = char:FindFirstChild('Left Arm') or char:FindFirstChild('LeftUpperArm')
| |
| 163 | local rl = char:FindFirstChild('Right Leg') or char:FindFirstChild('RightUpperLeg')
| |
| 164 | local ll = char:FindFirstChild('Left Leg') or char:FindFirstChild('LeftUpperLeg')
| |
| 165 | local root = char:FindFirstChild('HumanoidRootPart')
| |
| 166 | local rj = root:FindFirstChild('RootJoint')
| |
| 167 | local rs = ts:FindFirstChild('Right Shoulder')
| |
| 168 | local ls = ts:FindFirstChild('Left Shoulder')
| |
| 169 | local rh = ts:FindFirstChild('Right Hip')
| |
| 170 | local lh = ts:FindFirstChild('Left Hip')
| |
| 171 | local nk = ts:FindFirstChild('Neck')
| |
| 172 | local anim = char:FindFirstChild('Animate')
| |
| 173 | local base = workspace:FindFirstChild('Baseplate') or workspace:FindFirstChild('Base')
| |
| 174 | local cantimerewind = true | |
| 175 | local cooldown = false | |
| 176 | local selfrewind = true | |
| 177 | local cc = workspace.CurrentCamera | |
| 178 | local cos = math.cos | |
| 179 | local sin = math.sin | |
| 180 | local rad = math.rad | |
| 181 | local rand = math.random | |
| 182 | local cfn = CFrame.new | |
| 183 | local cfa = CFrame.Angles | |
| 184 | local v3 = Vector3.new | |
| 185 | local str = string | |
| 186 | local past = {}
| |
| 187 | local lastpast = {}
| |
| 188 | local sine = 0 | |
| 189 | local rewind = Instance.new('Sound', hd)
| |
| 190 | local onrewind = Instance.new('Sound', workspace.CurrentCamera)
| |
| 191 | onrewind.Looped = true | |
| 192 | onrewind.Volume = 10 | |
| 193 | onrewind.SoundId = 'rbxassetid://2061143306' | |
| 194 | rewind.SoundId = 'rbxassetid://864569342' | |
| 195 | rewind.Name = 'trewind' | |
| 196 | rewind.Volume = 1 | |
| 197 | rewind.PlaybackSpeed = 1.25 | |
| 198 | hum.WalkSpeed = 23 | |
| 199 | effects = Instance.new('Folder', char)
| |
| 200 | effects.Name = 'Effects' | |
| 201 | print([[ | |
| 202 | -- // Moves | |
| 203 | R - Rewind | |
| 204 | ]]) | |
| 205 | ||
| 206 | ArtificialHB = Instance.new('BindableEvent', script)
| |
| 207 | ArtificialHB.Name = 'Heartbeat' | |
| 208 | script:WaitForChild('Heartbeat')
| |
| 209 | ||
| 210 | frame = 1 / 60 | |
| 211 | tf = 0 | |
| 212 | allowframeloss = false | |
| 213 | tossremainder = false | |
| 214 | lastframe = tick() | |
| 215 | script.Heartbeat:Fire() | |
| 216 | ||
| 217 | game:GetService('RunService').Heartbeat:connect(function(s, p)
| |
| 218 | tf = tf + s | |
| 219 | if tf >= frame then | |
| 220 | if allowframeloss then | |
| 221 | script.Heartbeat:Fire() | |
| 222 | lastframe = tick() | |
| 223 | else | |
| 224 | for i = 1, math.floor(tf / frame) do | |
| 225 | script.Heartbeat:Fire() | |
| 226 | end | |
| 227 | lastframe = tick() | |
| 228 | end | |
| 229 | if tossremainder then | |
| 230 | tf = 0 | |
| 231 | else | |
| 232 | tf = tf - frame * math.floor(tf / frame) | |
| 233 | end | |
| 234 | end | |
| 235 | end) | |
| 236 | ||
| 237 | function swait(t) | |
| 238 | if t == 0 or t == nil then | |
| 239 | script.Heartbeat.Event:Wait() | |
| 240 | else | |
| 241 | for i = 0, t do | |
| 242 | script.Heartbeat.Event:Wait() | |
| 243 | end | |
| 244 | end | |
| 245 | end | |
| 246 | ||
| 247 | function sound(id, parent, vol, pitch, timepos) | |
| 248 | local s = Instance.new('Sound')
| |
| 249 | s.Parent = parent | |
| 250 | s.SoundId = id | |
| 251 | - | if str.lower(key) == 'r' and cantimerewind and cooldown == false then |
| 251 | + | |
| 252 | s.PlaybackSpeed = pitch | |
| 253 | - | elseif str.lower(key) == 'r' and cantimerewind == false and cooldown then |
| 253 | + | |
| 254 | s:Play() | |
| 255 | game.Debris:AddItem(s, s.PlaybackSpeed + 5) | |
| 256 | end | |
| 257 | ||
| 258 | function camshake(duration, intensity) | |
| 259 | coroutine.wrap(function() | |
| 260 | for i = 0, duration*60 do | |
| 261 | hum.CameraOffset = v3(rand(-(intensity*10),(intensity*10))/10, rand(-(intensity*10),(intensity*10))/10, rand(-(intensity*10), (intensity*10))/10) | |
| 262 | swait() | |
| 263 | end | |
| 264 | hum.CameraOffset = v3(0, 0, 0) | |
| 265 | end)() | |
| 266 | end | |
| 267 | ||
| 268 | function readyrewind() | |
| 269 | cantimerewind = false | |
| 270 | cooldown = true | |
| 271 | onrewind:Play() | |
| 272 | for i,v in pairs(workspace:GetDescendants()) do | |
| 273 | if v:IsA('BasePart') then
| |
| 274 | local lastpos = v.CFrame | |
| 275 | table.insert(past, {part = v, change = lastpos})
| |
| 276 | end | |
| 277 | if v.Parent then | |
| 278 | local lastparent2 = v.Parent | |
| 279 | table.insert(lastpast, {part2 = v, change4 = lastparent2})
| |
| 280 | end | |
| 281 | if v:IsA('Camera') then
| |
| 282 | local lastcam = v.CFrame | |
| 283 | table.insert(past, {cam = v, change3 = lastcam})
| |
| 284 | end | |
| 285 | if v:IsA('Sound') then
| |
| 286 | if v ~= rewind then | |
| 287 | local lastsongpos = v.TimePosition | |
| 288 | table.insert(past, {sound = v, pchange = lastsongpos})
| |
| 289 | end | |
| 290 | end | |
| 291 | if v:IsA('Humanoid') then
| |
| 292 | local lasthp = v.Health | |
| 293 | local always = lasthp | |
| 294 | table.insert(past, {health = v, hchange = lasthp})
| |
| 295 | end | |
| 296 | end | |
| 297 | newpast = workspace.DescendantAdded:Connect(function(v) | |
| 298 | if v:IsA('BasePart') then
| |
| 299 | local lastpos = v.CFrame | |
| 300 | local lastparent = v.Parent | |
| 301 | table.insert(past, {part = v, change = lastpos, change4 = lastparent})
| |
| 302 | end | |
| 303 | if v.Parent then | |
| 304 | local lastparent2 = v.Parent | |
| 305 | table.insert(lastpast, {part2 = v, change4 = lastparent2})
| |
| 306 | end | |
| 307 | if v:IsA('Camera') then
| |
| 308 | local lastcampos = v.CFrame | |
| 309 | table.insert(past, {cam = v, change3 = lastcampos})
| |
| 310 | end | |
| 311 | if v:IsA('Sound') then
| |
| 312 | if v ~= rewind then | |
| 313 | local lastsongpos = v.TimePosition | |
| 314 | table.insert(past, {sound = v, pchange = lastsongpos})
| |
| 315 | end | |
| 316 | end | |
| 317 | if v:IsA('Humanoid') then
| |
| 318 | local lasthp = v.Health | |
| 319 | local always = lasthp | |
| 320 | table.insert(past, {health = v, hchange = lasthp})
| |
| 321 | end | |
| 322 | end) | |
| 323 | end | |
| 324 | ||
| 325 | function timerewind() | |
| 326 | if cooldown then | |
| 327 | rewind:Play() | |
| 328 | sine = 0 | |
| 329 | onrewind:Stop() | |
| 330 | coroutine.wrap(function() | |
| 331 | local blur = Instance.new('BlurEffect', game.Lighting)
| |
| 332 | local effect2 = Instance.new('Part', effects)
| |
| 333 | local effect3 = Instance.new('Part', effects)
| |
| 334 | effect3.Shape = 'Ball' | |
| 335 | effect3.Material = 'ForceField' | |
| 336 | effect3.Anchored = true | |
| 337 | effect3.CanCollide = false | |
| 338 | effect3.Name = 'eff3' | |
| 339 | effect3.BrickColor = BrickColor.new('Really red')
| |
| 340 | effect3.Size = v3(30, 30, 30) | |
| 341 | effect3.Transparency = 0 | |
| 342 | effect2.CastShadow = false | |
| 343 | effect2.Shape = 'Ball' | |
| 344 | effect2.BrickColor = BrickColor.new('Bright red')
| |
| 345 | effect2.Material = 'ForceField' | |
| 346 | effect2.Name = 'eff2' | |
| 347 | effect2.Anchored = true | |
| 348 | effect2.CanCollide = false | |
| 349 | effect2.Size = v3(50, 50, 50) | |
| 350 | effect2.Transparency = 0 | |
| 351 | cantimerewind = true | |
| 352 | for i,v in pairs(past) do | |
| 353 | pcall(function() | |
| 354 | v.part.CFrame = v.change | |
| 355 | end) | |
| 356 | pcall(function() | |
| 357 | v.cam.CFrame = v.change3 | |
| 358 | end) | |
| 359 | pcall(function() | |
| 360 | v.sound.TimePosition = v.pchange | |
| 361 | end) | |
| 362 | pcall(function() | |
| 363 | v.health.Health = v.hchange | |
| 364 | end) | |
| 365 | end | |
| 366 | for i,v in pairs(lastpast) do | |
| 367 | pcall(function() | |
| 368 | v.part2.Parent = v.change4 | |
| 369 | end) | |
| 370 | end | |
| 371 | pcall(function() | |
| 372 | newpast:Disconnect() | |
| 373 | end) | |
| 374 | coroutine.wrap(function() | |
| 375 | for i = 1, 1000 do | |
| 376 | effect2.CFrame = ts.CFrame | |
| 377 | effect3.CFrame = ts.CFrame | |
| 378 | blur.Size = v3(blur.Size, 0, 0):lerp(v3(0, 0, 0), .010).X | |
| 379 | effect2.Transparency = effect2.Transparency + 0.020 | |
| 380 | effect3.Transparency = effect3.Transparency + 0.020 | |
| 381 | effect2.Size = effect2.Size:lerp(v3(0, 0, 0), 0.050) | |
| 382 | effect3.Size = effect3.Size:lerp(v3(0, 0, 0), 0.030) | |
| 383 | if effect2.Transparency >= 1 then | |
| 384 | effect2:Destroy() | |
| 385 | end | |
| 386 | if effect3.Transparency >= 1 then | |
| 387 | effect3:Destroy() | |
| 388 | end | |
| 389 | swait() | |
| 390 | end | |
| 391 | end)() | |
| 392 | wait(1) | |
| 393 | blur:Destroy() | |
| 394 | end)() | |
| 395 | wait(1.5) -- cooldown | |
| 396 | past = {}
| |
| 397 | cooldown = false | |
| 398 | end | |
| 399 | end | |
| 400 | ||
| 401 | mouse.KeyDown:connect(function(key) | |
| 402 | if str.lower(key) == 'c' and cantimerewind and cooldown == false then | |
| 403 | readyrewind() | |
| 404 | elseif str.lower(key) == 'c' and cantimerewind == false and cooldown then | |
| 405 | timerewind() | |
| 406 | end | |
| 407 | end) |