Try this I added some comments as I made a script like this along time ago.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local flashlight = script.Parent -- Assuming the flashlight is a child of the tool
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(0, 4000, 0) -- Adjust torque as needed
local function updateFlashlightOrientation()
local lookY = workspace.CurrentCamera.CFrame.LookVector.Y
local newYRotation = math.deg(math.asin(lookY)) -- Convert Y-axis value to degrees
bodyGyro.CFrame = CFrame.new(flashlight.Position) * CFrame.Angles(math.rad(newYRotation), 0, 0)
end
flashlight.Activated:Connect(function()
if not bodyGyro.Parent then
bodyGyro.Parent = flashlight
game:GetService("RunService").Heartbeat:Connect(updateFlashlightOrientation)
end
end)
flashlight.Deactivated:Connect(function()
if bodyGyro.Parent then
bodyGyro.Parent = nil
end
end)
Nevermind, I made this and it works just how I want it to:
--The "axis" being the camera.CFrame.LookVector.Y
script.Parent.Event.OnServerEvent:Connect(function(player,axis)
if player.Character and player.Character:FindFirstChild(script.Parent.Name) then
player.Character.Torso["Right Shoulder"].C0 = CFrame.new(player.Character.Torso["Right Shoulder"].C0.Position) * CFrame.Angles(0,math.rad(90),math.rad(axis*70))
else
player.Character.Torso["Right Shoulder"].C0 = CFrame.new(player.Character.Torso["Right Shoulder"].C0.Position) * CFrame.Angles(0,math.rad(90),0)
end
end)
Im going to be posting this solution onto the Community Tutorials page, because I haven’t seen any solutions like mine.