So i’m trying to make this bites the dust thing from JoJo (an anime), and it reverses time. I’m trying to make it so you teleport back to where you were 30 seconds ago, but I don’t know how to do so.
Store where they are now. Fast foward 30 seconds teleport them to that position. You could probably do this via setting the HumanoidRootPart
’s .CFrame
property or the Model:MoveTo
method.
Example code:
local players = game:GetService("Players")
local client = players.LocalPlayer
local character = client.Character
local humanoidRootPart = character.humanoidRootPart
local currentPosition = humanoidRootPart.CFrame
wait(30)
humanoidRootPart.CFrame = currentPosition
No , the OP wants to teleport them to their 30 second-past location not fast forward,
Well to do what you want @Aaroncy , you’ll need to consider memory at a point, if you’re going to be doing this time-shift repetitively.
You could save the Player’s humanoid.Position every 30 seconds in a loop to a vector 3 value until a point , in a folder Parented to the player, and then 30 seconds later you could use Humanoid:MoveTo then to that previously saved position.
edit : I see you’ve edited your post accordingly, nice work
What. Reread my post
I am talking about storing the position at the time frame of the script just running, not 30 seconds since. What I said still applies; by Fast forward
I meant wait 30 seconds in some way
The best way to this is to probably record the player’s position every 30 seconds, then simply set their CFrame using the HumanoidRootPart
back to that position.
(Edited)
(just an example)
-----local script
local PreviousPosition = Player.Character.HumanoidRootPart.Position
while true do
wait(30)
PreviousPosition = Player.Character.HumanoidRootPart.Position
end
function Reverse()
Player.Character.HumanoidRootPart.Position = PreviousPosition
end
This would not work because you overwrite both CurrentPosition
and PreviousPosition
after the 30 seconds…
Here is something that should work.
local previousPosition = nil;
while true do
previousPosition = player.Character:FindFirstChild('HumanoidRootPart').CFrame;
wait(30)
player.Character:FindFirstChild('HumanoidRootPart').CFrame = previousPosition
end
That would generally work, but that would only apply for 30 second intervals. If the person wants to go back in time after 15 or 10 seconds (instead of 30), the position you saved would technically be incorrect.
Instead have a table that saves a position every second with a max of 30. Once the table reaches 30, have the very first element you saved (from about 30 seconds ago) removed and then shift all the elements in the table to make room for the new position and keep the size of the table to 30. When you time travel, you simply move to the first position on the table (which should be the position saved 30 seconds ago). Then a debounce of 1 second on time travel would stop any random errors and you’re good to go.
basically:
local poses = {} --this is the table
--filling the positions (needs 30 in total)
for i=1, 30 do
poses[i] = player.Character.HumanoidRootPart.Position
end
while wait(1) do
table.remove(poses, 1)
poses[30] = player.Character.HumanoidRootPart.Position
end
--[[Insert Time Travel Here]]