How to make tool move with mouse?

Video of the Issue:
https://vimeo.com/777167798

How can I make the tool move with my mouse? I’m using R15 in my game & would like other players in the game to see the player’s arm movement.

I’ve tried looking at many old dev posts but either:

a. the scripts don’t work
b. the post is convoluted & unclear

I’ve also tried looking up videos on Youtube but there doesn’t seem to be a video about this.

1 Like
local RunService = game:GetService("RunService")



local Player = game.Players.LocalPlayer

local PlayerMouse = Player:GetMouse()



local Camera = workspace.CurrentCamera



local Character = Player.Character or Player.CharacterAdded:Wait()

local Head = Character:WaitForChild("Head")

local Neck = Head:WaitForChild("Neck")

local Torso = Character:WaitForChild("UpperTorso")
local Waist = Torso:WaitForChild("Waist")

local Arm = Character:WaitForChild("RightUpperArm")

local Shoulder = Arm:WaitForChild("RightShoulder")



local Humanoid = Character:WaitForChild("Humanoid")

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")



local NeckOriginC0 = Neck.C0

local ShoulderOriginC0 = Shoulder.C0

local WaistOriginC0 = Waist.C0



Neck.MaxVelocity = 1/2



RunService.RenderStepped:Connect(function()

	local CameraCFrame = Camera.CoordinateFrame



	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then

		local ArmLookVector = Arm.CFrame.lookVector

		local HeadPosition = Head.CFrame.p
		
		local TorsoLookVector = Torso.CFrame.lookVector


		if Neck and Shoulder and Waist then

			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then

				local Point = PlayerMouse.Hit.p



				local Distance = (Head.CFrame.p - Point).magnitude

				local Difference = Head.CFrame.Y - Point.Y



				Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance) ), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)

				Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
				
				Waist.C0 = Waist.C0:lerp(WaistOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5, 0), 0.5 / 2)
				
			end

		end

	end	

end)

I inserted this script into StartPlayerScripts and added a part w/ a spotlight to the flashlight (a little bit in front of the flashlight)

1 Like

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