So I am trying to make a tool aim towards either Mouse.Hit or Mouse.Origin. Right now, I am using Mouse.Hit, but the gun is becoming really glitchy. Why?
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Equipped = false script.Parent.Equipped:connect(function() Equipped = true coroutine.resume(coroutine.create(function() script.Parent.Parent.Animate.Disabled = true Mouse.Move:connect(function() if Equipped == true then local Angles = Mouse.Hit - Mouse.Hit.p script.Parent.Parent.Torso["Right Shoulder"].C0 = CFrame.new(script.Parent.Parent.Torso["Right Shoulder"].C0.p, Mouse.Hit.p) wait() end end) script.Parent.Parent.Animate.Disabled = false end)) end) script.Parent.Unequipped:connect(function() Equipped = false end)
I feel like this should work, but instead it just flings my arm around. Also, there is no output from the script.
I'm not certain of what the issue is - your code looks good.
What it might be is that coroutine. Why are you using it, anyway? It doesn't need to be there, since the callback function is spawned in its own thread when it gets called.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Equipped = false script.Parent.Equipped:connect(function() Equipped = true script.Parent.Parent.Animate.Disabled = true Mouse.Move:connect(function() if Equipped == true then local Angles = Mouse.Hit - Mouse.Hit.p script.Parent.Parent.Torso["Right Shoulder"].C0 = CFrame.new(script.Parent.Parent.Torso["Right Shoulder"].C0.p, Mouse.Hit.p) wait() end end) script.Parent.Parent.Animate.Disabled = false end) script.Parent.Unequipped:connect(function() Equipped = false end)
Let me know if this worked for you, because there is a way to make the aiming a lot smoother than using Mouse.Move
.