Hello, so I am editing an existing script to rotate the arm with the mouse position. But when I disconnect the RunService. I try something to return the arm to its original position. But I got these bugs. I don’t know how to solve it.
The Script :
function RotateArm()
local connection
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
mouse.TargetFilter = workspace
local Torso = char:WaitForChild("Torso")
local armOffset = Torso.CFrame:Inverse() * char["Right Arm"].CFrame
local armWeld = Instance.new("Weld")
local InitialPosition = char["Right Arm"].CFrame
armWeld.Part0 = Torso
armWeld.Part1 = char["Right Arm"]
armWeld.Parent = char
local lastmou
connection = RunService.RenderStepped:Connect(function()
lastmou = mouse.Hit.p
local cframe = CFrame.new(Torso.Position, mouse.Hit.Position) * CFrame.new(0,0.5,-0.5) * CFrame.Angles(math.pi/2, 0, 0)
armWeld.C0 = armOffset * Torso.CFrame:toObjectSpace(cframe)
end)
wait(3)
connection:Disconnect()
armWeld.C0 = InitialPosition
end
RotateArm()
The Video