How do I make this Part's CFrame Always be equal to the Players CFrame?

The Grey Brick is Slacking off and I need it to stay with the character at all times.
Bad Part, :frowning:
Or how would I make this script faster?

robloxapp-20200328-1417123.wmv (755.4 KB)
^Video^

The Grey Part Needs to be Anchored for Reasons

while Humanoid:GetPropertyChangedSignal("CFrame") do
	wait(.000000000000000000000000000000000000001)
	print(Humanoid.CFrame)
    OtherPart.CFrame = Humanoid.CFrame
end	
3 Likes

There’s no need to put a wait there. Also, a wait that small doesn’t exit. The wait() minimum value is about .03333.

If this is a local script use RunService and its RenderStepped event to run this function every single frame so it’ll never lag behind.

can RunService work on a nomal Script?

1 Like

If you want make the “part” stay in character all time, use Weld.

1 Like

If I use a Weld on an Anchored part then the player stays suspended in mid air

1 Like

The unanchor the welded part, should be fine.

1 Like

I suggest you to make an anchored part and weld it to the humanoid to use it.
If you would like to use what you gave us however, here’s what you could do.

HumanoidRootPart = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Connect(function()
    Part.CFrame = HumanoidRootPart.CFrame
end)
2 Likes

the part has to be anchored for something else

Yes it can. You can run Stepped which fires before the physics step, or Heartbeat which fires after it.

1 Like

use a weld, set the Part0 to the HumanoidRootPart, then set Part1 to the Part, make sure the Part is cancollide false so it doesnt fling your character around, if you do that then there is no need for the Loop. but if you do want to use a loop, use RunService.Stepped

game:GetService('RunService').Stepped:Connect(function()
     Part.CFrame = Character.PrimaryPart.CFrame
end)

it would look better for the client to use RenderStepped Also

2 Likes

Oh and instead of doing wait(.000000000000000000000000000000000000001), just do wait()

Instead of doing wait do game:GetService(“RunService”).Stepped:Wait() or .RenderStepped:Wait().
:wink:
Depending on if you want 1/30th of a second on Server or 1/60th on client

Edit: Reference here
Edit: Fixed the timings I had wrong because I was way too tired when I originally posted this and forgot how timings worked.

1 Like

The difference between Stepped and RenderStepped is what point of the frame they run at. They both run every frame, so each will be every 1/60th of a second.

Here’s a handy chart that I think(?) was shown at an RDC presentation: made by zeuxcg and beautified by Fractality_alt:
image

3 Likes

I was always under the impression that .Stepped was physics and RenderStepped was graphics.

Edit: My reference for what I said.

And you’re right, I was wrong on the timing, as it’s 1/30th on Server and 1/60th on Client because the client runs at 60 FPS and the server at 30.

1 Like

Yes, looking at the chart you can see that RenderStepped runs before Render (you want to do graphics stuff before it renders) and Stepped runs before Physics (you want to apply forces/etc. before Roblox tries to handle them).

3 Likes

Yup. I know. In my state of tiredness at my time of writing the response before forgot that it was anything the server did was 1/30 and the client was 1/60. I use these functions all the time though.

1 Like