TimeModule:Track(BasePart part) -- Track the given object.
TimeModule:Untrack(BasePart part) -- Stop tracking the given object.
TimeModule:SetSpeed(unsigned integer speed) -- Set the speed. Only works when in reverse.
TimeModule:IsReverse() -- Returns whether time is in reverse or not.
TimeModule:Reverse() -- Reverse time.
TimeModule:Unreverse() -- Unreverse time. Note that this doesnt replay all next frames, it lets time go back to normal after a reverse.
TimeModule:Update(float deltaTime) -- Store the current position of all tracked parts.
Here’s an example script that should roughly show you how to use the module:
local runService = game:GetService('RunService')
local players = game:GetService('Players')
local player = players.LocalPlayer
local timeModule = require(script.Parent:WaitForChild('TimeModule'))
local button = script.Parent
local char = player.Character or player.CharacterAdded:Wait()
wait(1) -- wait for the character to spawn in, so we can track it too
for _,v in ipairs(workspace:GetDescendants()) do
if v:IsA('BasePart') then
timeModule:Track(v)
end
end
button.MouseButton1Down:Connect(function()
timeModule:Reverse()
timeModule:SetSpeed(2)
end)
while true do
timeModule:Update(0.1) -- 0.1 is the delta time(time difference between every update)
wait(0.1)
end
This will reverse time with twice the speed once the button is clicked.
Contribute
Want to help make this module better? Feel free to make a pull request here:
Fin
I hope you have fun programming with this module! I can’t wait to see the cool stuff you make with it.
Please tell me if you have any suggestions, or if you find bugs. Have a great day.
(sorry if the post is low-quality, i rushed it a bit)
I feel updating the parts data every frame regardless of if it has moved or not is not the most efficient solution to carry out this task, perhaps look into having a property changed signal for each part’s position which is being tracked, then it may be more practical for people to incorporate into their games.
@LuaBearyGood Great suggestion! I’ll add that as soon as possible. Storing the CFrame of every part every frame is definitely not optimal, I’ll try out something like interpolating between each CFrame.
Definitely an idea although I’m not sure how well that’s work when you have a huge array of parts. Creating event listeners for each object could end up being more costly than saving it on a frame basis as there’s very little cost in doing so.
Hello. I have noticed you on your demo game that your reversal script is ran on a local script.
Not just that but the module script is in the GUI and not ReplicatedStorage.
#1. Expensive operations like this that need to be framelocked to look right should be on the client, nothing of this workload should be on the server for this reason
#2. Does it matter where he puts the module? It doesn’t matter as long as he requires it. As a matter of fact, if the module isn’t being used by multiple scripts, then it’d make even more sense to put the module just around the area where you need it
I could see some epic puzzle games being made off of this idea in the future!
Edit: Also, does the module track the scale of parts, or just the CFrame?