Why is Cframe.lookAt() not working?

So I am trying to make a part point towards a position.
When i have run into this error


Why is this happeing?

local function fireBullet(player, tool, po)
	local rs = game:GetService('RunService')
	local poPart = Instance.new('Part')
	poPart.Position = po
	local bullet = game:GetService('ReplicatedStorage'):FindFirstChild('Bullet'):Clone()
	bullet.Position = tool:FindFirstChild('Handle').Position
	bullet.Parent = workspace
	print(po)
	bullet.CFrame = CFrame.lookAt(poPart.Position)
	rs.Heartbeat:Connect(function()
		bullet.CFrame = bullet.CFrame * CFrame.new(1,0,0)
	end)
end
1 Like

change this line and see if it’s fixed.
bullet.CFrame = CFrame.lookAt(CFrame.new(poPart.Position))

Same things still happening.
It needs a Vecter3 not a cframe

then try vector3.new
character limit

Still not working.
Anymore ideas?

bullet.CFrame = CFrame.lookAt(Vector3.new(poPart.Position), Vector3.new(bullet.CFrame))

If po is where it should be facing, use it as the second parameter and the first should be the bullet position.

bullet.CFrame = CFrame.lookAt(bullet.Position, po)
1 Like

Well this works for the most part.
Except that it is making it point 90 degrees off.
How do I make it turn by 90 degrees?

Add CFrame.Angle(math.rad(90), 0, 0), if the direction is still not correct, change math.rad to the other axis until it rotates correctly, also try with -90.

bullet.CFrame = CFrame.lookAt(bullet.Position, po) * CFrame.Angle(math.rad(90), 0, 0)

This is not having any effect on it.

Did you try other math.rad positions?

yes I did
Still not working
I have no idea how to fix this

Try this, it should work.

local function fireBullet(player, tool, po)
    local rs = game:GetService('RunService')
    local bullet = game:GetService('ReplicatedStorage'):FindFirstChild('Bullet'):Clone()
    bullet.Position = tool:FindFirstChild('Handle').Position
    bullet.Parent = workspace
    bullet.CFrame = CFrame.lookAt(bullet.Position,po) * CFrame.Angles(math.rad(90),0,0)
    rs.Heartbeat:Connect(function()
        bullet.CFrame = bullet.CFrame * CFrame.new(1,0,0)
        if not bullet then
            break -- dont keep too many heartbeats
        end
    end)
end

It may be a bit late, but I hope it helps.

I figured it out!
I just had to change which direction it moves in!

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