You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!r
A flashlight that follows your cursor -
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) -
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.