Hello! I’m having a weird bug when my arm still following my mouse after I unequipped the tool, how do I fix it?
Equipping tool:
Unequipping tool:
The Code:
local run = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local char = player.Character
if not char or not char.Parent then
char = player.CharacterAdded:Wait()
end
local tool = script.Parent
local mouse = player:GetMouse()
local function OnEquipped()
run.RenderStepped:Connect(function()
local rightX, rightY, rightZ = char.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
char.Torso["Right Shoulder"].C0 = (char.Torso["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((mouse.Hit.p - mouse.Origin.p).unit.y))
local leftX, leftY, leftZ = char.Torso["Left Shoulder"].C0:ToEulerAnglesYXZ()
char.Torso["Left Shoulder"].C0 = (char.Torso["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-mouse.Hit.p - -mouse.Origin.p).unit.y))
end)
end
tool.Equipped:Connect(OnEquipped)
Thanks for reading and thanks for helping!