-- AUTO-REPLAY (with Playback saves) local Players = game:GetService("Players") local UIS = game:GetService("UserInputService") local RunService = game:GetService("RunService") local HttpService = game:GetService("HttpService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local camera = workspace.CurrentCamera -- settings local REPLAY_CAMERA = true -- also replay where the camera was looking local recording, playing = false, false local frames, events = {}, {} local recStart = 0 local recConn, playConn local lastTool = nil local saves = {} -- list of { id, name, duration, frames, events } local nextId = 1 local currentPlayId = nil -- id of the save currently playing local dirty = false -- true when saves changed and need syncing to the cloud local loadDone = true -- false while cloud saves are still loading local function markDirty() dirty = true end ---------------------------------------------------------------- GUI local gui = Instance.new("ScreenGui") gui.Name = "AutoReplayGui" gui.ResetOnSpawn = false gui.Parent = player:WaitForChild("PlayerGui") local frame = Instance.new("Frame") frame.Size = UDim2.fromOffset(360, 300) frame.Position = UDim2.new(0, 20, 0.5, -150) frame.BackgroundColor3 = Color3.fromRGB(30, 30, 35) frame.Active = true frame.Draggable = true frame.Parent = gui Instance.new("UICorner", frame) local title = Instance.new("TextLabel") title.Size = UDim2.new(1, 0, 0, 28) title.BackgroundTransparency = 1 title.Text = "AUTO-REPLAY" title.Font = Enum.Font.GothamBold title.TextSize = 16 title.TextColor3 = Color3.new(1, 1, 1) title.Parent = frame local status = Instance.new("TextLabel") status.Size = UDim2.new(1, 0, 0, 20) status.Position = UDim2.fromOffset(0, 28) status.BackgroundTransparency = 1 status.Text = "Idle" status.Font = Enum.Font.Gotham status.TextSize = 13 status.TextColor3 = Color3.fromRGB(180, 180, 180) status.Parent = frame -- name box for the next recording local nameBox = Instance.new("TextBox") nameBox.Size = UDim2.new(1, -20, 0, 26) nameBox.Position = UDim2.fromOffset(10, 52) nameBox.BackgroundColor3 = Color3.fromRGB(45, 45, 52) nameBox.PlaceholderText = "Name (optional)" nameBox.PlaceholderColor3 = Color3.fromRGB(130, 130, 140) nameBox.Text = "" nameBox.ClearTextOnFocus = false nameBox.Font = Enum.Font.Gotham nameBox.TextSize = 13 nameBox.TextColor3 = Color3.new(1, 1, 1) nameBox.Parent = frame Instance.new("UICorner", nameBox) -- button row local btnRow = Instance.new("Frame") btnRow.Size = UDim2.new(1, -20, 0, 30) btnRow.Position = UDim2.fromOffset(10, 84) btnRow.BackgroundTransparency = 1 btnRow.Parent = frame local rowLayout = Instance.new("UIListLayout") rowLayout.FillDirection = Enum.FillDirection.Horizontal rowLayout.Padding = UDim.new(0, 6) rowLayout.Parent = btnRow local function makeButton(parent, text, color, size) local b = Instance.new("TextButton") b.Size = size b.BackgroundColor3 = color b.Text = text b.Font = Enum.Font.GothamBold b.TextSize = 11 b.TextWrapped = true b.TextColor3 = Color3.new(1, 1, 1) b.AutoButtonColor = true b.Parent = parent Instance.new("UICorner", b) return b end local startBtn = makeButton(btnRow, "Start - Begin Replay", Color3.fromRGB(200, 60, 60), UDim2.new(0.45, -4, 1, 0)) local stopBtn = makeButton(btnRow, "Stop", Color3.fromRGB(90, 90, 100), UDim2.new(0.2, -4, 1, 0)) local playBtn = makeButton(btnRow, "PLAY", Color3.fromRGB(60, 160, 80), UDim2.new(0.35, -4, 1, 0)) -- saves header local savesTitle = Instance.new("TextLabel") savesTitle.Size = UDim2.new(1, -20, 0, 20) savesTitle.Position = UDim2.fromOffset(10, 122) savesTitle.BackgroundTransparency = 1 savesTitle.Text = "Playback saves" savesTitle.Font = Enum.Font.GothamBold savesTitle.TextSize = 13 savesTitle.TextXAlignment = Enum.TextXAlignment.Left savesTitle.TextColor3 = Color3.fromRGB(220, 220, 220) savesTitle.Parent = frame -- scrolling list of saves local list = Instance.new("ScrollingFrame") list.Size = UDim2.new(1, -20, 1, -150) list.Position = UDim2.fromOffset(10, 144) list.BackgroundColor3 = Color3.fromRGB(22, 22, 26) list.BorderSizePixel = 0 list.ScrollBarThickness = 6 list.CanvasSize = UDim2.new(0, 0, 0, 0) list.AutomaticCanvasSize = Enum.AutomaticSize.Y list.ScrollingDirection = Enum.ScrollingDirection.Y list.Parent = frame Instance.new("UICorner", list) local listLayout = Instance.new("UIListLayout") listLayout.Padding = UDim.new(0, 4) listLayout.SortOrder = Enum.SortOrder.LayoutOrder listLayout.Parent = list local listPad = Instance.new("UIPadding") listPad.PaddingTop = UDim.new(0, 4) listPad.PaddingBottom = UDim.new(0, 4) listPad.PaddingLeft = UDim.new(0, 4) listPad.PaddingRight = UDim.new(0, 4) listPad.Parent = list local emptyLabel = Instance.new("TextLabel") emptyLabel.Size = UDim2.new(1, 0, 0, 30) emptyLabel.BackgroundTransparency = 1 emptyLabel.Text = "No saves yet" emptyLabel.Font = Enum.Font.Gotham emptyLabel.TextSize = 12 emptyLabel.TextColor3 = Color3.fromRGB(120, 120, 130) emptyLabel.Parent = list ---------------------------------------------------------------- minimize local FULL_SIZE = frame.Size local MINI_SIZE = UDim2.fromOffset(170, 28) local minimized = false local minBtn = makeButton(frame, "-", Color3.fromRGB(70, 70, 80), UDim2.fromOffset(24, 20)) minBtn.Position = UDim2.new(1, -30, 0, 4) minBtn.TextSize = 16 minBtn.MouseButton1Click:Connect(function() minimized = not minimized for _, child in ipairs(frame:GetChildren()) do if child:IsA("GuiObject") and child ~= title and child ~= minBtn then child.Visible = not minimized end end frame.Size = minimized and MINI_SIZE or FULL_SIZE minBtn.Text = minimized and "+" or "-" if not minimized then emptyLabel.Visible = (#saves == 0) end end) ---------------------------------------------------------------- helpers local function getChar() local char = player.Character if not char then return end local hum = char:FindFirstChildOfClass("Humanoid") local root = char:FindFirstChild("HumanoidRootPart") if hum and root then return char, hum, root end end local function addEvent(kind, data) table.insert(events, { t = os.clock() - recStart, kind = kind, data = data }) end local function formatDuration(seconds) local m = math.floor(seconds / 60) local s = seconds - m * 60 return ("%d:%04.1f"):format(m, s) end ---------------------------------------------------------------- recording local inputConns = {} local startPlaying, stopPlaying -- forward declarations local addSaveRow local function stopRecording() if not recording then return end recording = false if recConn then recConn:Disconnect() end for _, c in ipairs(inputConns) do c:Disconnect() end table.clear(inputConns) if #frames < 2 then status.Text = "Recording too short" return end -- save it to the list local id = nextId nextId += 1 local name = nameBox.Text if name:gsub("%s", "") == "" then name = "Replay " .. id end local save = { id = id, name = name, duration = frames[#frames].t, loopMode = "off", -- "off", "tp" (instant teleport) or "walk" (smooth return) frames = frames, events = events, } table.insert(saves, save) addSaveRow(save) markDirty() nameBox.Text = "" status.Text = ("Saved \"%s\" (%s)"):format(save.name, formatDuration(save.duration)) end local function startRecording() if recording or playing or not loadDone then return end local _, hum, root = getChar() if not root then return end frames, events = {}, {} lastTool = nil recStart = os.clock() recording = true status.Text = "Recording..." -- movement / position sampled every frame recConn = RunService.Heartbeat:Connect(function() local char, h, r = getChar() if not r then return end table.insert(frames, { t = os.clock() - recStart, cf = r.CFrame, move = h.MoveDirection, vel = r.AssemblyLinearVelocity, state = h:GetState(), -- player stats ws = h.WalkSpeed, jp = h.JumpPower, jh = h.JumpHeight, useJP = h.UseJumpPower, hip = h.HipHeight, slope = h.MaxSlopeAngle, grav = workspace.Gravity, -- camera cam = camera.CFrame, fov = camera.FieldOfView, }) -- equipped tool changes local tool = char:FindFirstChildOfClass("Tool") local name = tool and tool.Name or nil if name ~= lastTool then lastTool = name addEvent("equip", name) end end) -- jumps table.insert(inputConns, UIS.JumpRequest:Connect(function() addEvent("jump") end)) -- any key / mouse button / touch table.insert(inputConns, UIS.InputBegan:Connect(function(input, processed) local ut = input.UserInputType if ut == Enum.UserInputType.MouseButton1 or ut == Enum.UserInputType.Touch then addEvent("click", { pos = input.Position, processed = processed }) elseif ut == Enum.UserInputType.Keyboard then addEvent("key", { code = input.KeyCode, down = true }) end end)) table.insert(inputConns, UIS.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then addEvent("key", { code = input.KeyCode, down = false }) end end)) end ---------------------------------------------------------------- playback local controls do local ok, result = pcall(function() return require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls() end) if ok then controls = result end end local DRIFT_LIMIT = 3 -- studs before we snap you back onto the recording local originals = nil -- stats/camera settings to restore after playback local function captureOriginals(h) originals = { ws = h.WalkSpeed, jp = h.JumpPower, jh = h.JumpHeight, useJP = h.UseJumpPower, hip = h.HipHeight, slope = h.MaxSlopeAngle, grav = workspace.Gravity, camType = camera.CameraType, fov = camera.FieldOfView, } end local function restoreOriginals(h) if not originals then return end if h then h.WalkSpeed = originals.ws h.UseJumpPower = originals.useJP h.JumpPower = originals.jp h.JumpHeight = originals.jh h.HipHeight = originals.hip h.MaxSlopeAngle = originals.slope end workspace.Gravity = originals.grav camera.CameraType = originals.camType camera.FieldOfView = originals.fov originals = nil end function stopPlaying() if not playing then return end playing = false currentPlayId = nil if playConn then playConn:Disconnect() end local _, hum = getChar() if hum then hum:Move(Vector3.zero, false) end restoreOriginals(hum) if controls then controls:Enable() end -- give control back status.Text = "Idle" end local function applyStats(h, f) h.WalkSpeed = f.ws h.UseJumpPower = f.useJP if f.useJP then h.JumpPower = f.jp else h.JumpHeight = f.jh end h.HipHeight = f.hip h.MaxSlopeAngle = f.slope workspace.Gravity = f.grav end local RETURN_TIMEOUT = 15 -- seconds before a stuck "smooth return" teleports instead local ARRIVE_DIST = 3 -- studs from the start point that counts as "arrived" function startPlaying(save) if recording or playing then return end if not save or #save.frames < 2 then status.Text = "Nothing recorded yet" return end local _, hum, root = getChar() if not root then return end local pFrames, pEvents = save.frames, save.events local first = pFrames[1] playing = true currentPlayId = save.id if controls then controls:Disable() end -- stops your real input fighting the replay captureOriginals(hum) local phase = "play" -- "play" or "return" local t0, fi, ei local loops = 1 local returnStart = 0 local function setStatus() if save.loopMode ~= "off" then status.Text = ('Looping "%s" (#%d)'):format(save.name, loops) else status.Text = ('Playing "%s"...'):format(save.name) end end -- (re)start the recording from its first frame local function beginRun(r) r.CFrame = first.cf r.AssemblyLinearVelocity = Vector3.zero phase = "play" t0 = os.clock() fi, ei = 1, 1 if REPLAY_CAMERA then camera.CameraType = Enum.CameraType.Scriptable end setStatus() end beginRun(root) playConn = RunService.Heartbeat:Connect(function() local char, h, r = getChar() if not r then stopPlaying() return end ----------------------------------------------------- SMOOTH RETURN phase if phase == "return" then applyStats(h, first) local toStart = Vector3.new(first.cf.Position.X - r.Position.X, 0, first.cf.Position.Z - r.Position.Z) if toStart.Magnitude <= ARRIVE_DIST or os.clock() - returnStart > RETURN_TIMEOUT then h:Move(Vector3.zero, false) loops += 1 beginRun(r) else h:Move(toStart.Unit, false) -- real walking, so animations play end return end ----------------------------------------------------- PLAY phase local t = os.clock() - t0 -- replay events while ei <= #pEvents and pEvents[ei].t <= t do local e = pEvents[ei] if e.kind == "jump" then h.Jump = true elseif e.kind == "equip" then if e.data == nil then h:UnequipTools() else local tool = player.Backpack:FindFirstChild(e.data) or char:FindFirstChild(e.data) if tool then h:EquipTool(tool) end end elseif e.kind == "click" then local tool = char:FindFirstChildOfClass("Tool") if tool then tool:Activate() end end ei += 1 end -- recording finished: stop, or loop depending on the save's loop mode if t >= pFrames[#pFrames].t then if save.loopMode == "tp" then loops += 1 beginRun(r) -- instant teleport back to the start elseif save.loopMode == "walk" then phase = "return" -- walk back to the start returnStart = os.clock() camera.CameraType = originals and originals.camType or Enum.CameraType.Custom status.Text = ('Returning to start... "%s"'):format(save.name) else stopPlaying() end return end -- find the two frames around the current time while fi < #pFrames - 1 and pFrames[fi + 1].t <= t do fi += 1 end local a, b = pFrames[fi], pFrames[fi + 1] local alpha = math.clamp((t - a.t) / math.max(b.t - a.t, 1e-6), 0, 1) local target = a.cf:Lerp(b.cf, alpha) -- apply the stats you had at this moment (speed, jump height, etc.) applyStats(h, a) -- the Humanoid walks for real, so the walk/run/jump/fall animations play h:Move(a.move, false) -- only correct position if we've drifted too far from the recording if (r.Position - target.Position).Magnitude > DRIFT_LIMIT then r.CFrame = target r.AssemblyLinearVelocity = a.vel:Lerp(b.vel, alpha) end -- camera if REPLAY_CAMERA then camera.CFrame = a.cam:Lerp(b.cam, alpha) camera.FieldOfView = a.fov + (b.fov - a.fov) * alpha end end) end ---------------------------------------------------------------- saves list local function refreshEmpty() emptyLabel.Visible = #saves == 0 end function addSaveRow(save) local row = Instance.new("Frame") row.Name = "Save_" .. save.id row.Size = UDim2.new(1, -8, 0, 32) row.BackgroundColor3 = Color3.fromRGB(40, 40, 46) row.LayoutOrder = save.id row.Parent = list Instance.new("UICorner", row) local nameLabel = Instance.new("TextLabel") nameLabel.Size = UDim2.new(1, -210, 1, 0) nameLabel.Position = UDim2.fromOffset(8, 0) nameLabel.BackgroundTransparency = 1 nameLabel.Text = save.name nameLabel.Font = Enum.Font.GothamMedium nameLabel.TextSize = 11 nameLabel.TextXAlignment = Enum.TextXAlignment.Left nameLabel.TextTruncate = Enum.TextTruncate.AtEnd nameLabel.TextColor3 = Color3.new(1, 1, 1) nameLabel.Parent = row local durLabel = Instance.new("TextLabel") durLabel.Size = UDim2.fromOffset(40, 32) durLabel.Position = UDim2.new(1, -202, 0, 0) durLabel.BackgroundTransparency = 1 durLabel.Text = formatDuration(save.duration) durLabel.Font = Enum.Font.Gotham durLabel.TextSize = 11 durLabel.TextColor3 = Color3.fromRGB(170, 170, 180) durLabel.Parent = row local playRowBtn = makeButton(row, "Play", Color3.fromRGB(60, 160, 80), UDim2.fromOffset(38, 24)) playRowBtn.Position = UDim2.new(1, -160, 0.5, -12) local delBtn = makeButton(row, "Delete", Color3.fromRGB(190, 60, 60), UDim2.fromOffset(46, 24)) delBtn.Position = UDim2.new(1, -50, 0.5, -12) -- loop button: click to cycle Off -> TP (instant teleport) -> Walk (smooth return) local loopBtn = makeButton(row, "Loop: Off", Color3.fromRGB(70, 70, 80), UDim2.fromOffset(64, 24)) loopBtn.Position = UDim2.new(1, -118, 0.5, -12) loopBtn.TextSize = 10 local loopStyles = { off = { text = "Loop: Off", color = Color3.fromRGB(70, 70, 80) }, tp = { text = "Loop: TP", color = Color3.fromRGB(50, 110, 200) }, walk = { text = "Loop: Walk", color = Color3.fromRGB(130, 80, 200) }, } local nextMode = { off = "tp", tp = "walk", walk = "off" } loopBtn.MouseButton1Click:Connect(function() save.loopMode = nextMode[save.loopMode] local st = loopStyles[save.loopMode] loopBtn.Text = st.text loopBtn.BackgroundColor3 = st.color end) playRowBtn.MouseButton1Click:Connect(function() startPlaying(save) end) delBtn.MouseButton1Click:Connect(function() if currentPlayId == save.id then stopPlaying() end for i, s in ipairs(saves) do if s.id == save.id then table.remove(saves, i) break end end row:Destroy() refreshEmpty() markDirty() end) refreshEmpty() end ---------------------------------------------------------------- cloud saving -- Needs the server script (AutoReplayServer) in ServerScriptService. local SAVE_RATE = 30 -- frames per second kept in the cloud copy local MAX_JSON = 3500000 -- DataStore limit is ~4MB, keep a margin local SYNC_EVERY = 1 -- seconds between checks for changes local saveRemote, loadRemote local cloudOk = false local function r(n, d) local m = 10 ^ d return math.floor(n * m + 0.5) / m end local function setIdleStatus(text) if not recording and not playing then status.Text = text end end local stateByValue = {} for _, st in ipairs(Enum.HumanoidStateType:GetEnumItems()) do stateByValue[st.Value] = st end local function packCF(cf) local rx, ry, rz = cf:ToOrientation() return r(cf.X, 2), r(cf.Y, 2), r(cf.Z, 2), r(rx, 3), r(ry, 3), r(rz, 3) end local function encodeEvent(e) local o = { t = r(e.t, 3), k = e.kind } if e.kind == "key" then o.d = { c = e.data.code.Name, dn = e.data.down } elseif e.kind == "click" then o.d = { x = r(e.data.pos.X, 1), y = r(e.data.pos.Y, 1), p = e.data.processed } else o.d = e.data end return o end local function decodeEvent(o) local data = o.d if o.k == "key" then local ok, code = pcall(function() return Enum.KeyCode[data.c] end) data = { code = ok and code or Enum.KeyCode.Unknown, down = data.dn } elseif o.k == "click" then data = { pos = Vector3.new(data.x, data.y, 0), processed = data.p } end return { t = o.t, kind = o.k, data = data } end -- turns a save into a small JSON-friendly table local function encodeSave(sv) local out = { id = sv.id, name = sv.name, d = r(sv.duration, 3), f = {}, s = {}, e = {} } local lastKept = -1 local lastStats = nil local total = #sv.frames for i, fr in ipairs(sv.frames) do if i == total or fr.t - lastKept >= 1 / SAVE_RATE then lastKept = fr.t local idx = #out.f + 1 local px, py, pz, prx, pry, prz = packCF(fr.cf) local cx, cy, cz, crx, cry, crz = packCF(fr.cam) out.f[idx] = { r(fr.t, 3), px, py, pz, prx, pry, prz, r(fr.move.X, 2), r(fr.move.Y, 2), r(fr.move.Z, 2), r(fr.vel.X, 1), r(fr.vel.Y, 1), r(fr.vel.Z, 1), fr.state.Value, cx, cy, cz, crx, cry, crz, r(fr.fov, 1), } -- stats (speed, jump, gravity...) only stored when they change local stats = { idx, r(fr.ws, 2), r(fr.jp, 2), r(fr.jh, 2), fr.useJP and 1 or 0, r(fr.hip, 2), r(fr.slope, 1), r(fr.grav, 2), } local changed = lastStats == nil if not changed then for k = 2, 8 do if stats[k] ~= lastStats[k] then changed = true break end end end if changed then table.insert(out.s, stats) lastStats = stats end end end for _, e in ipairs(sv.events) do table.insert(out.e, encodeEvent(e)) end return out end local function decodeSave(o) local fr = {} local nextStat = 1 local cur for i, f in ipairs(o.f) do while o.s[nextStat] and o.s[nextStat][1] <= i do cur = o.s[nextStat] nextStat += 1 end fr[i] = { t = f[1], cf = CFrame.new(f[2], f[3], f[4]) * CFrame.fromOrientation(f[5], f[6], f[7]), move = Vector3.new(f[8], f[9], f[10]), vel = Vector3.new(f[11], f[12], f[13]), state = stateByValue[f[14]] or Enum.HumanoidStateType.Running, cam = CFrame.new(f[15], f[16], f[17]) * CFrame.fromOrientation(f[18], f[19], f[20]), fov = f[21], ws = cur[2], jp = cur[3], jh = cur[4], useJP = cur[5] == 1, hip = cur[6], slope = cur[7], grav = cur[8], } end local ev = {} for _, e in ipairs(o.e) do table.insert(ev, decodeEvent(e)) end return { id = o.id, name = o.name, duration = o.d, frames = fr, events = ev, enc = o } end -- checks every second; only sends to the server when something changed task.spawn(function() while true do task.wait(SYNC_EVERY) if dirty and cloudOk then dirty = false local list = {} for _, sv in ipairs(saves) do sv.enc = sv.enc or encodeSave(sv) table.insert(list, sv.enc) end local okEnc, json = pcall(HttpService.JSONEncode, HttpService, { v = 1, saves = list }) if not okEnc then warn("[AUTO-REPLAY] couldn't encode saves: " .. tostring(json)) elseif #json > MAX_JSON then setIdleStatus("Too much data to save - delete some saves") else local okSend, accepted = pcall(function() return saveRemote:InvokeServer(json) end) if okSend and accepted then setIdleStatus("Saves synced") else dirty = true -- try again next second end end end end end) -- load saves from the last visit loadDone = false task.spawn(function() status.Text = "Loading saves..." saveRemote = ReplicatedStorage:WaitForChild("AutoReplaySave", 10) loadRemote = ReplicatedStorage:WaitForChild("AutoReplayLoad", 10) if not (saveRemote and loadRemote) then status.Text = "Idle (no server script - saves won't persist)" loadDone = true return end local ok, result = pcall(function() return loadRemote:InvokeServer() end) if not ok or result == false then status.Text = "Couldn't load cloud saves - not saving" loadDone = true return end if type(result) == "string" and result ~= "" then local okDec, data = pcall(HttpService.JSONDecode, HttpService, result) if not (okDec and type(data) == "table" and type(data.saves) == "table") then status.Text = "Cloud save data unreadable - not saving" loadDone = true return end for _, o in ipairs(data.saves) do local okS, sv = pcall(decodeSave, o) if okS then table.insert(saves, sv) nextId = math.max(nextId, sv.id + 1) addSaveRow(sv) else warn("[AUTO-REPLAY] skipped a broken save") end end end cloudOk = true loadDone = true status.Text = ("Idle - %d saves loaded"):format(#saves) end) ---------------------------------------------------------------- buttons startBtn.MouseButton1Click:Connect(startRecording) stopBtn.MouseButton1Click:Connect(function() stopRecording() stopPlaying() end) -- main PLAY button replays the most recent save playBtn.MouseButton1Click:Connect(function() startPlaying(saves[#saves]) end)