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.
- 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!
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
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.