Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- How to Use:
- Press Record button to record. Hit it again to stop recording.
- Enter a number in the Replay Possession box and press enter to replay a recording.
- Limitation: The tracked instances MUST have unique names.
- ]]
- local Possessions = {}
- local Runservice = game:GetService("RunService")
- -- The Parts that are tracked
- local Tracked = {
- [1] = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait(),
- ["Ball"] = workspace:WaitForChild("Ball"),
- }
- local replaying = false
- local recording
- function recordInstanceForTime(i: number)
- local table = {}
- for _, character in pairs(Tracked) do
- if character:IsA("Model") then
- table[character.Name] = {}
- for _, v in pairs(character:GetChildren()) do
- if v:IsA("BasePart") then
- table[character.Name][v.Name] = v.CFrame
- end
- end
- else
- table[character.Name] = character.CFrame
- end
- end
- Possessions[#Possessions][i] = table
- end
- function disableJoints(rig: Model)
- for _, v in pairs(rig:GetDescendants()) do
- if v:IsA("JointInstance") then
- if v.Part0.Parent ~= rig or v.Part1.Parent ~= rig then
- continue
- end
- v.Enabled = false
- elseif v:IsA("BasePart") and v.Parent == rig then
- v.Anchored = true
- v.CanCollide = false
- end
- end
- end
- function startReplay(currentPossession: number)
- -- Prevent replaying if recording or already replaying
- if recording or replaying or currentPossession > #Possessions then
- return
- end
- replaying = true
- local Models = {}
- local tb = Possessions[currentPossession]
- for _, v: Instance in pairs(Tracked) do
- v.Archivable = true
- local rig = v:Clone()
- rig.Parent = workspace
- disableJoints(rig)
- v.Archivable = false
- Models[v.Name] = rig
- end
- for _, gotPossession in pairs(tb) do
- for character, bodyParts in pairs(gotPossession) do
- if typeof(bodyParts) == "CFrame" then
- Models[character].CFrame = bodyParts
- else
- for i, v in pairs(bodyParts) do
- Models[character][i].CFrame = v
- end
- end
- end
- task.wait()
- end
- for _, v in pairs(Models) do
- v:Destroy()
- end
- Models = nil
- replaying = false
- end
- local function startRecording()
- if replaying then
- return
- end
- if recording then
- recording:Disconnect()
- recording = nil
- script.Parent:WaitForChild("recording").Text = "Recording : false"
- return
- end
- Possessions[#Possessions + 1] = {}
- script.Parent:WaitForChild("Possessions").Text = "Amount Of Possessions : " .. #Possessions
- local time = 0
- recording = Runservice.RenderStepped:Connect(function()
- recordInstanceForTime(time)
- time += 1
- end)
- script.Parent:WaitForChild("recording").Text = "Recording : true"
- end
- script.Parent:WaitForChild("recording").MouseButton1Click:Connect(function()
- startRecording()
- end)
- script.Parent:WaitForChild("TextBox").FocusLost:Connect(function(enterPressed)
- if enterPressed then
- startReplay(tonumber(script.Parent:WaitForChild("TextBox").Text))
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement