So as I described in the title, the gun is fully functional, but when you double(or more) click and hold it's like it's running multiple threads. I've tried adding debounces but I'm still puzzled. The problem is at the mouse.Button1down function (at the bottom). Let me know you if have any alternate ways of scripting this. Thanks :)
function fire() --Cloning stuff, direction ETC, everything's working here end local button1down = false function Active() while button1down == true do local player = game.Players.LocalPlayer local humanoid = player.Character.Humanoid if humanoid == nil then print("Humanoid not found") return end local player = game.Players.LocalPlayer local mouse = player:GetMouse() wait(.3) fire() end end local player = game.Players.LocalPlayer local mouse = player:GetMouse() local mouse = game.Players.LocalPlayer:GetMouse() mouse.Button1Down:connect(function() button1down = true Active() end) mouse.Button1Up:connect(function() button1down = false print('off') end)
That is NOT a debounce, that is a variable that poorly connect/disconnects a function, also, you should not use a while loop
var = nil current = tick() --Set up the loop, tick() sends the time function active() if current - tick() < .3 then return end current = tick() --Reset the position of "current" --stuff end) push:connect(function() var = game:GetService('RunService').Stepped:connect(Active) --hold the connection in a variable, like you do in Clone() end) release:connect(function() if var then var:disconnect() end --INSTANTLY DISCONNECTS -- "if bool then" is equal to "if bool == true then" -- "if object then" is equal to "if object ~= nil then" --"if string then" does not exist end)
What's happening is that during the wait() is that if the variable is changed, it cannot check it because it only checks at the end of the loop function. However if you disconnect, the function will disconnect the function from the loop.