Clicking works great. Pressing “G” and enabling Gatling mode works fine as well. But if you’re holding down click, and you unequip, the error appears. I checked the syntax, I checked the logic, unless I’m a complete idiot, this script just breaks for literally no reason.
I went through many iterations where I checked if the mouse was not nil.
“if mouse then”
“if not mouse then break end”
“if not mouse return end”
On almost every line.
It just keeps breaking. The script ignores me, and says “no no, there’s a mouse, we’ll continue” and then when they meet up with the “fire(mouse.Hit.p)” function, it freaks out. “WHAT THE- WHERE’S THE MOUSE THERE’S NO MOUSE ill break now”
I’ve tried consulting Scripting Helpers, friends, and this is my last resort. I have to assume this is just some annoying bug with no work around. And I need a work around.
I was able to stop the error from arising (even though the error doesn’t actually break the script, it seems) by changing the while shooting do loop to this:
while shooting do
wait()
hum = char:FindFirstChild("Humanoid")
if hum == nil then else
if hum.Health <= 0 then shooting = false end
if pcall(function() _=mouse['Hit']; end) then
fire(mouse.Hit.p)
if not AUTOFIRE then
shooting = false
end
wait(COOLDOWN)
end
end
[quote] I was able to stop the error from arising (even though the error doesn’t actually break the script, it seems) by changing the while shooting do loop to this:
while shooting do
wait()
hum = char:FindFirstChild("Humanoid")
if hum == nil then else
if hum.Health <= 0 then shooting = false end
if pcall(function() _=mouse['Hit']; end) then
fire(mouse.Hit.p)
if not AUTOFIRE then
shooting = false
end
wait(COOLDOWN)
end
end [/quote]
THANK YOU!
I apologize for the inconvenience then, since this wasn’t a true bug report.
I know this is old, but I do not recommend that anyone does it this way, because his code is very inefficient. not only are pcalls slow, but also the reason that it can’t find your mouse is that you are using a nested function like this:
’
This is a problem because every time you equip the tool, it creates a new activated function, meaning that when you equip, unequip then equipt it, it will have two functions printing hello, and if you unequip and equip again, it prints hello 3 times. You only need one of those to be running because you only need to do the action once.
’
Now on to why it is erroring, It is doing the exact same thing except the hello statement is your mouse. It is creating a new mouse every time you equip the tool, but Roblox by default makes the old mouse inactive, so with the old mouse, it throws an error, but with the new mouse still works, which is why it throws an error and works at the same time.
Solution1 (Tool mouse):
local mouse = nil
script.Parent.Equipped:Connect(function(m)
mouse = m
end)
script.Parent.Activated:Connect(function()
print(mouse.Hit.p)
end)
These are my observations, but now i wonder, why does everyone always do nested functions with the activated inside of the equipped one? Is there a big reason that i am missing?
@trytry1 because Tool.Equipped’s first parameter gets the mouse, so from there you can start making something that requires a mouse while tool is equipped. You cannot get the mouse from outside the function unless you use player:GetMouse() so i guess the only solution is to put the activated function in equipped (Unless you like to be extremely complicated, I guess you use Players:GetPlayerFromCharacter(player) then player:GetMouse())