Changing CFrame of the Primary Part

Why does it happen?..


wait(5)

local rocket = game.ReplicatedStorage.Abilities.TestRocket:Clone()

rocket.Name = "SUPERROCKET"

rocket.Parent = workspace

print(game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position)
print(CFrame.new(game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position).Position)

rocket.PrimaryPart.CFrame = CFrame.new(game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position)

rocket.PrimaryPart.Anchored = true

local TweenService = game:GetService("TweenService")

print(rocket.PrimaryPart.CFrame.Position)

The first print statement gives you the position of the humanoid root part of SpecialRig. The second print statement gives you the same thing, but as the position component of a new cframe. The third print statement gives you the position of the primary part of the clone of TestRocket.

but I previously set PrimaryPart position to game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position
How it can differ when I try to print it?

Is the primarypart collidable? If so, it could be pushing your RootPart and create that difference in position. Turn off CanColldie if its on.

Sorry for not noticing that. That does make things a lot more confusing and I don’t actually know the answer to why. Might have something to do with the fact that setting cframes won’t check for overlaps between parts and physics will then make it make sense, but that’s only a guess. I only know that the documentation suggests to use the PivotTo method instead, which should be easy enough to implement. Might look something along the lines of changing rocket.PrimaryPart.CFrame = CFrame.new(game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position) to rocket.PrimaryPart:PivotTo(CFrame.new(game.Workspace.SpecialRig.HumanoidRootPart.CFrame.Position))

Or putting rocket.PrimaryPart.Anchored = true above that line so that it is anchored before the physics solver tries to do anything funny.

I solved it. It was really because of
rocket.PrimaryPart.Anchored = true.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.