Heyo I’m trying to make an ability that lets the player go back a certain amount of time for example if the player wants to go back 2minutes or 120seconds everything they did within the last 2minutes will be undone currently I’m trying to do this with their position. every 5 seconds I just put their current position in a dictionary if the position isn’t the same as the last one in the dictionary along with an os.time() so I know what time they were their at
while Character do
if not Actions[Character.Name] then
Actions[Character.Name] = {
["Movement"] = {}
}
end
if Length(Actions[Character.Name]["Movement"]) == 0 then
table.insert(Actions[Character.Name]["Movement"],{Character.HumanoidRootPart.Position,math.floor(tick()-CurrentTime)})
end
local LastPosition = Actions[Character.Name]["Movement"][Length(Actions[Character.Name]["Movement"])]
if LastPosition[1] ~= Character.HumanoidRootPart.Position then
warn("New Position at "..os.time()-CurrentTime)
table.insert(Actions[Character.Name]["Movement"],{Character.HumanoidRootPart.Position,math.floor(os.time()-CurrentTime)})
end
wait(3)
end
And with this code I can just put them back at the position with the time they sent
Remotes.RewindTime.OnServerEvent:Connect(function(Player,Time)
local AmountToGoBack = tonumber(Time)
for i,v in pairs(Actions[Player.Name]["Movement"]) do
if v[2] == AmountToGoBack then
Player.Character.HumanoidRootPart.Position = v[1]
end
end
end)
However I realized the way I setup saving the time of the position doesn’t make sense because if I move to a different position and stand their for 3minutes and then wanted to back to the last position I have to go back 180 seconds so that’s what I should put, but with my current code I have to actually write like 18 which is because I’m doing os.clock()-CurrentTime (a variable I made at the start of the script) which is basically the time of when the game started (I think) SO basically my question is how can I put like a proper timer for this?