Problem with rotating a part

I want to attach a part to the players head that is constantly rotating towards the Mouse.Hit position. The part has a spotlight inside of it so it acts as an headlight. Does somebody know how to do this

Heres the script I have it doesnt work:

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Part = Instance.new('Part')

Part.CanCollide = false
Part.Size = Vector3.new(0.5,0.5,0.5)
Part.Anchored = true
Part.Parent = workspace
Part.Transparency = 1

local SpotLight = Instance.new('SpotLight')
SpotLight.Parent = Part
SpotLight.Enabled = true
SpotLight.Brightness = 1
SpotLight.Range = 6
SpotLight.Angle = 60

local mouse = Player:GetMouse()

game:GetService("RunService").RenderStepped:Connect(function()
	
	local newCFrame = CFrame.lookAt(Char.Head.Position, mouse.Hit.Position)
	Part.CFrame = newCFrame

end)

Probably a while loop or something with run service that checks the mouse.hit position and changes the orientation accordingly.

Your script seems to be working fine, the spot light is just not bright enough.


image

1 Like