Making the spotlight's parent look at mouse's position

I’m welding a part that has Spotlight as a child to HumanoidRootPart as .Part1 (parented to the character), and the direction the part looks at seems to be correct.

However, whenever I look down or up, my character decides to fling, and other weird scenarios. What seems to be the issue here?

--light is the Spotlight's parent (part)
light.CFrame = CFrame.lookAt(light.Position, mouse.Hit.p)

Example of the issue.

2 Likes

I’m guessing this is a tool, like a flashlight?
Make sure all the Parts in your tools have the Massless Property set to true so their weight doesn’t affect the Humanoid.

2 Likes

It’s meant to be a flashlight, but it’s a part with a spotlight that gets cloned in the player’s character:
image
I tried setting the .Massless to true, but it seemed to not help as much.

Not sure if the welding has something to do with this, but I’ll see if I get different results.

local root = char.HumanoidRootPart
		
local clone = light:Clone()
clone.Parent = char; clone.Position = root.Position
		
local weld = Instance.new("WeldConstraint"); weld.Parent = clone
weld.Part0 = clone; weld.Part1 = root

Is that the only Part in the tool, or are there other Parts as well? If there are more then make them all massless.

1 Like

No, that’s all that’s being cloned, it’s not parented to a tool.

Do you see the Part at all? Why not just instance a Spotlight in the HumanoidRootPart?

The part is always in the same position (to HumanoidRootPart). I wanted to create an effect so the flashlight moves with the cursor (or camera), as seen above - not static in a spot.

Sorry, got distracted and forgot it was aiming with the cursor.
Is it CanCollide on?

1 Like

The CanCollide is false to the part.
image

But your Massless is set to false.
Also try turning off CanTouch as well.

1 Like

Still have the same issue (even with massless). Is there a better alternative for this? I don’t feel like CFrame.lookAt() would do the job here.

Here’s the place file if you want to test it:
flashlightDebug.rbxl (30.5 KB)

1 Like

local script:

local SL = Instance.new("SurfaceLight")
SL.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart

That should be it i hope… :slight_smile:

You can take advantage of this model I think it is close to the thing you want to do You can give up the tool if you want to

1 Like

May I suggest using an attachment in the humanoid root part instead?

1 Like