How to made model follow cursor

I have a certain spotlight model that should follow the cursor, but it doesn’t seem to follow the cursor when its a model.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local Head = game.Workspace.Spotlight1.Arm.Head

Mouse.Move:connect(function()
	local MousePosition = Mouse.Hit.p
	Head.CFrame = CFrame.new(Head.Position,MousePosition)
end)

Any way to fix this?

(Extra question: Is there a way to make it so the part only follows the mouse on the x or y axis?)

Do you want the part to move to the cursor or rotate to face the cursor?

The model should rotate to always face the cursor.

Try:

Mouse.Move:Connect(function()
	local MousePosition = Mouse.Hit.Position
	Head.CFrame = CFrame.lookAt(Head.Position, MousePosition)
end)

Not working.

It could be cause the naming for the position of a model is different, from a part, but I’m not sure.

Ah, it’s a model?

Is it possible to union all the parts together or weld them all together so they can move together?

Sadly, no.

There are a few mesh parts making it up since it’s a detailed model.

Alright, can you try and weld everything?

I welded everything (with use of a plugin).

I have a previous script that allows the spotlight to move using WASD keys.

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

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.A 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, -0.05, 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.A then return end
	if not UpdateCon then return end

	UpdateCon:Disconnect()
	UpdateCon = nil
end)

It moves the entire object using the A key.
Is there any way to change this into looking at the cursor?

If you want to rotate a model, use PivotTo().

Model:PivotTo(CFrame.new(Model.WorldPivot.Position, direction))

Correct? Or no

You would change “direction” to the mouse position. Also, don’t set “head.worldpivot”, just keep head:PivotTo()

It does follow the cursor now, however, it follows the cursor facing the wrong way.

Instead of the light pointing at the cursor, the bottom of the part is facing it.
Any way to fix this?

(Going back to the extra question: how can i make it only follow the cursor on the x or y axis?)

Try and set the CFrame.Orientation -= or += 90?

You can edit the pivot point of the model using a button at the top of studio (not sure exactly where) and then rotate it 180°. To make it only rotate in x and y you can do this:

local direction = Vector3.new(mouseposition.X,Model.WorldPivot.Position.Y,mouseposition.Z)
Model:PivotTo(CFrame.new(Model.WorldPivot.Position, direction))

How may I implement this into this script?

Mouse.Move:Connect(function()
	local MousePosition = Mouse.Hit.Position
	local direction = Vector3.new(MousePosition.Z,Head.WorldPivot.Position.Y,MousePosition.Y)
	Head:PivotTo(CFrame.new(Head.WorldPivot.Position, direction))
end)

You may need to make a new Model to hold the Spotlight and add a motor to the Arm and move it that way. I have not used motors in a while, but this should work.
local Player = game:GetService(“Players”).LocalPlayer
local Mouse = Player:GetMouse()
local Spotlight = Instance.new(“Model”, game.Workspace)
local Arm = Instance.new(“Part”, Spotlight)
Arm.Name = “Arm”
local Head = Instance.new(“Part”, Spotlight)
Head.Name = “Head”
local ArmMotor = Instance.new(“Motor6D”, Arm)
ArmMotor.Part0 = Arm
ArmMotor.Part1 = Head

Head.CFrame = game.Workspace.Spotlight1.Arm.Head.CFrame

Mouse.Move:connect(function()
local MousePosition = Mouse.Hit.p
ArmMotor.C0 = CFrame.new(Arm.Position,MousePosition)
end)