Problem with CFrame.lookAt

Hello everyone, I am trying to make a script that activates when the mouse button is clicked and it would turn the part to the mouse with CFrame.lookAt. The problem I have right now is that the part won’t tilt the right way it is supposed to.

local Players = game:GetService("Players")
 
local player = Players.LocalPlayer
local Lookpart = workspace.VFX:WaitForChild("lookpart")
local Mouse = player:GetMouse()
local mPosition = Mouse.Hit.Position

Mouse.Button1Up:Connect(function(player) 

	
	Lookpart.CFrame = CFrame.lookAt(Lookpart.Position, mPosition)


end)

The script is in a local script in the starter pack please give me some more intel about CFrame.lookAt so I won’t make the same mistake twice.

Thanks a lot

Define mPosition inside the Button1Up function. The variable is only getting the initial mouse position because it’s defined when the script starts

this is the problem I have right now

local Players = game:GetService("Players")
 
local player = Players.LocalPlayer
local Lookpart = workspace.VFX:WaitForChild("lookpart")
local Mouse = player:GetMouse()

Mouse.Button1Up:Connect(function(player) 

	local mPosition = Mouse.Hit.Position -- define it here to get the new position
	Lookpart.CFrame = CFrame.lookAt(Lookpart.Position, mPosition)


end)
1 Like