Need help making model follow cursor

I have a spotlight model, that currently moves using the WASD keys.

Here it is in use:

I want to make it so that it instead starts to follow the cursor when I press a key and stops following it when I press another key. I’m not sure if I have to do anything with Cframe though, like Cframe.lookat for example.

Here is the script that moves the spotlight forward when you press W:

local userInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local SpotlightHead = game.Workspace.Spotlight1.Arm.Head
local UpdateCon

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.W then return end

	if UpdateCon then
		UpdateCon:Disconnect()
		UpdateCon = nil
	end

	UpdateCon = RunService.Heartbeat:Connect(function(dt)
		local newCFrame = SpotlightHead.PrimaryPart.CFrame * CFrame.Angles(-0.05, 0, 0)
		SpotlightHead:SetPrimaryPartCFrame(newCFrame)
	end)
end)

userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.W then return end
	if not UpdateCon then return end

	UpdateCon:Disconnect()
	UpdateCon = nil
end)

Any help is appreciated! :slight_smile:

Have you tried using CFrame.lookvector to make the model point to the player’s mouse cursor position?