Using CFrame.lookAt is flinging me when used in a tool

Hello, I am attempting to use CRFrame.lookAt to make a part (within a flashlight tool) called “light_part” that always looks where the mouse points. This is a first-person game so It’s the center of the screen. light_part is a small, massless, transparent, non-collideable cube with a point light on it.

Using CFRrame.lookAt is flinging me…
See video:


Please forgive the quality. The video needed to be compressed to 10 MB or less.

I can only assume this is happening because light_part is held to the rest of the model using a weldconstraint. Since the light_part is attached to the rest of the model and it’s position and rotation are constantly updated to my head’s AND my character is holding it, it’s creating a sort of feedback loop reminiscent of a Minecraft flying machine that pushes itself.

Screenshot 2024-05-31 193846

- Side note, the script named “Script” just plays a sound and turns the point light within light_part on/off when the tool is toggled. The only properties being changed by that script are the material/color of the inside “cone” of the flashlight, and enabling/disabling the point light.

I am running the CFrame.lookAt script via a LocalScript because I don’t want the light coming out of the player’s head serverside. Here is the script:

local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = script.Parent.cone.light_part

RunService.RenderStepped:Connect(function()
	part.CFrame = CFrame.lookAt(part.Position, mouse.Hit.Position)
end)

I’m not quite sure how to go about fixing this. I have tried searching for the past hour for a solution or something even remotely similar. Any help is greatly appreciated. Thank you!

2 Likes

Can’t wait to see a gigabrain that knows how to fix it instantly like it’s nothing :smiling_face_with_tear:

since the tool is connected to your character, its teleporting the tool (and you) to wherever your mouse is every 1/60th of a second (im pretty sure thats how fast renderstepped is)

if you want your flashlight to go where your mouse is, you need to make a script that rotates your arm instead

1 Like

I have a very stupid solution:
detach it from your character and spawn and move the lightpart seperately

(teamassist’s solution is way better lol)

I have no clue how I’d go about doing that. I could only find stuff about how to do it using R15, hence why I tried to do it this way :confused:

try this Help rotating arm correctly

I did A LOT more digging today and found a post with my exact situation for R6 characters. It’s not perfect as it’s a bit choppy and doesn’t have much horizontal movement, but it allows vertical movement with the tool, which is more than enough for me.

Thank you so much to everyone who helped out!

See the post here:

Never knew my old community tutorial would end up here.

1 Like

Your post helped me out more than I could ever imagine. Thank you so much for the time and effort you put into it! :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.