CFrame flying across the map to a very far position + how to ignore a certain rotation axis?

I am currently trying to learn CFrame and attempting to point a part towards a player (their humanoidrootpart), but after testing some things to try and ignore the Y axis (for rotation / orientation) and reverting it, the parts being moved by CFrame are just flying across the map in milliseconds.

The script:


local char


--cframe 
local t = script.Parent.mainpart

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:wait()
	char = player.Character
end)

game:GetService("RunService").Heartbeat:Connect(function()
	if char ~= nil then
		t.CFrame = CFrame.new(t.Position + char.HumanoidRootPart.Position)
	end
end)

I feel like it might not be a problem with the script, if this is confirmed I can tell the layout of the parts being moved by CFrame (theyre welded)

The part moving has to do with you setting it’s position to be it’s postion + the characters position, instead try

t.Cframe = Cframe.new(t.Position,char.HumanoidRootPart.Position)

You should look at CFrames | Documentation - Roblox Creator Hub

1 Like

Would you know how to not change the X axis though?
I’ve tried:

t.CFrame = CFrame.new(t.Position, char.HumanoidRootPart.Position * Vector3.new(0,1,1))

It just prevents the CFrame from really moving at all

So I’m a bit confused about what exactly your trying to do. But I guess you could

local char


--cframe 
local t = script.Parent.mainpart

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:wait()
	char = player.Character
end)

local x = t.Cframe.X

game:GetService("RunService").Heartbeat:Connect(function()
	if char ~= nil then
		t.CFrame = CFrame.new(t.Position,char.HumanoidRootPart.Position)
                t.Cframe.X = x
	end

The cframe is really only facing toward the root it won’t move anywhere unless you change the first of the cframe.new values

t.Cframe = Cframe.new(positioningVector,facetowardthisVector)
1 Like