How can I repeat and delay a singular line of code?

Currently I am trying to create a cosmic clone and I have made a script to copy the players position. I need to add a delay to when the rig follows the player. I have tried using task.delay() but whenever I use it with the loop, it exhausts the loop. Here is my current code:

local clone = game.ReplicatedStorage.Rig:Clone()
clone.Parent = workspace
local Player = script.Parent.Parent
local Character = Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")

while true do
	clone.HumanoidRootPart.CFrame = Root.CFrame
	task.wait(0.01)
end
1 Like

What do you mean by “Add a delay”,
You want a sort of ghost like effect ?

I want the delay to be similar to cosmic clones from Super Mario Galaxy 2.

What i would do, first, get the player CFrame, wait, then set your cloone CFrame. and i would use a task.Spawn in order to have
not sure but i would have done it like this:

local clone = game.ReplicatedStorage.Rig:Clone()
clone.Parent = workspace
local Player = script.Parent.Parent
local Character = Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")

While true do
     Task.Spawn(Function()
         local CRoot = Root.CFrame
         Task.wait(0.01)
         clone.HumanoidRootPart.CFrame = CRoot
     end)
     Task.Wait()
end

that’s not optimised, but it’s worth trying

The same thing as with the original script happens when I try your script.

What’s happening clearly, what’s the console output ?

I see nothing in the output from the script

Do you have a video of what’s happening ?

I don’t know how to post a video on the forums and I also don’t know how to record in studio.

Alright, try to describe in details what’s happening, what you see, etc…

  • at first, does your clone rig work ? does it appear ?
  • Second, does it follow the player, or does it stuck to the player, like it’s anchored to it

You can use the print(“”) to see if your loop is running as well, that would help to see what’s wrong

The loop is properly working and the rig does appear. The rig also follows the player but there is no delay between when the player moves and the rig moves so the rig is constantly at the exact position and orientation of the player.

If you want to have a 1 second delay, you have to change the task.wait(0.01) to 1.
the task.wait will is your delay.
Don’t touch the empty task.wait() since it’s here for the loop

Nothing has changed besides the fact that the rig is vibrating is how I would describe it.

A video would really be helpful.
in the “View” studio tab, you got a video recording button.
Then you can just upload it to youtube and share the link
image

The issue with that is that I don’t have a Youtube account.

Here is at least an image if it helps.

I think you can just record it, convert the file from WMV (roblox video format, don’t ask why…) into a MP4, and just post it here like an image, should work

Here is a video of what happens.

local clone = game.ReplicatedStorage.Rig:Clone()
clone.Parent = workspace
local Player = script.Parent.Parent
local Character = Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")

While true do
     Task.Spawn(Function()
         local CRoot = Root.CFrame
         Task.wait(1)
         clone.HumanoidRootPart.CFrame = CRoot
     end)
     Task.Wait()
end

It’s like that, right ?

That is the current version of the script I am using.