Rotating flashlight is off by 90 degrees

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!r
    A flashlight that follows your cursor
  2. What is the issue? Include screenshots / videos if possible!
    It rotates the wrong way 90* (its an edit of someone else’s follow cursor script, for tool & R6 compatibility)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
local Equipped = false
script.Parent.Equipped:Connect(function()
	Equipped = true
end)
script.Parent.Unequipped:Connect(function()
	Equipped = false
end)
--- Services ---
local Players = game:GetService("Players");
local RunService = game:GetService("RunService");
wait();

--- Declarations ---
local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();

local Mouse = Player:GetMouse();

--- Character ---
local RightUpperArm = Character:WaitForChild("Right Arm");
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
local RightShoulder = Character:WaitForChild("Torso"):WaitForChild("Right Shoulder");
--- Execution ---
RunService.Stepped:Connect(function()
	if Equipped == true then
		local hit = Mouse.Hit;

		-- add the lookVector * 5000 to the hit.p to make the point more "dramatic" (remove it and you'll see why I did this)
		local direction = hit.p + (hit.lookVector * 100000);

		-- get the rotation offset (so the arm points correctly depending on your rotation)
		local rootCFrame = HumanoidRootPart.CFrame;
		local rotationOffset = (rootCFrame - rootCFrame.p):inverse();

		-- since CFrames are relative, put the rotationOffset first, and then multiple by the point CFrame, and then multiple by the CFrame.Angles so the arm points in the right direction
		RightShoulder.Transform = (rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 2, 0, 0));
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Try removing the CFrame angles?

Adding on to DrMystery’s reply, just try different values for the rotation in the part of the code above to rotate it different directions.

If you want that in degrees (instead of radians) use:

CFrame.Angles(math.rad(degreesX), math.rad(degreesY), math.rad(degreesZ))

What does “degrees(value)” mean?

math.deg converts a degree number (e.g. 0 degrees through 360 degrees) to a unit of degrees called radians (0*pi through 2*pi).

You can test out different rotations by filling in degreesX, degreesY, and degreesZ with different values, eg:

CFrame.Angles(math.rad(90), math.rad(0), math.rad(-90))

Edit:

@MysteryX2076 Yes I did, thanks for catching that! That’s fixed in the posts above.

Did you mean math.rad instead? math.deg converts radians into degrees e.g. math.deg(math.pi) = 180 degrees

1 Like