I'm trying to mimic the effect in those Dragon Ball games where your character follows your mouse as you're about to shoot something. This is a local script in a hopperbin:
player = game.Players.LocalPlayer
repeat wait() until player.Character
char = player.Character
active = false
function onSelected(mouse)
active = true
local gyro
if not char.Torso:FindFirstChild("FollowMouseGyro") then
gyro = Instance.new("BodyGyro", char.Torso)
gyro.Name = "FollowMouseGyro"
gyro.maxTorque = Vector3.new(math.huge, math.huge, math.huge)
end
while active do
gyro.cframe = CFrame.new(char.Torso.CFrame.p, mouse.Hit.p)
game:GetService("RunService").RenderStepped:wait()
end
end
script.Parent.Selected:connect(onSelected)
script.Parent.Deselected:connect(function()
active = false
if char.Torso:FindFirstChild("FollowMouseGyro") then
char.Torso.FollowMouseGyro:Destroy()
else return
end
end)
And that will give me the "Mouse no longer active" error whenever I deselect the hopperbin, but it will still work just fine. How do I get rid of this error?
