This is only a partial answer.
The reason the arm is spinning wildly is that you aren't returning the shoulder to its original state each frame. To undo multiplying by a CFrame, you can multiply by its inverse.
Minor: debounce is the variable name traditionally used to prevent a function from running multiple times simultaneously. You're using it as a "continue to operate" variable (maybe just call it "equipped", "keepRunning/Executing", or just "run/execute"?)
Here's a partially fixed script:
local tool = script.Parent
local localPlayer = game.Players.LocalPlayer
local lastcf, rsh, run
tool.Equipped:connect(function(mouse)
run = true
lastcf = nil
while run do
wait(0.1)
rsh = localPlayer.Character.Torso["Right Shoulder"]
if lastcf then
rsh.C1 = rsh.C1 * lastcf:inverse()
end
local cf = CFrame.new(Vector3.new(0, 0, 0), mouse.Origin.lookVector) * rsh.C1:inverse()
rsh.C1 = rsh.C1 * cf
lastcf = cf
end
if lastcf then
rsh.C1 = rsh.C1 * lastcf:inverse()
end
end)
tool.Unequipped:connect(function()
run = false
end)
Also, note that using the character's Torso won't work with the R15 character models.
Further, rsh = game.Players.LocalPlayer.Character.Torso["Right Shoulder"] is error prone -- if the Torso doesn't exist, the script will error. Using FindFirstChild("Torso") doesn't help if you then don't check if it returns nil! We can rewrite that bit like so:
local torso = localPlayer.Character:FindFirstChild("Torso")
if not torso then return end
rsh = torso["Right Shoulder"]
The problem with the script is the line local cf = CFrame.new(Vector3.new(0, 0, 0), mouse.Origin.lookVector) * rsh.C1:inverse(). I know that you want the lookVector of mouse.Origin (the direction that the user is looking), not mouse.Origin.p (which is sort of the position of the camera), but I don't know what to do with it after that.
3 comments
Is this the full script?
no there is some other stuff that is irrelevent
try CFrame.Angles instead of CFrame.new