Ad
Log in to vote
0

I want to make a gun and bypass a tool, but I'm having debounce problems? [Figured it out myself] [closed]

Asked by 7 years ago

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)

Locked by Orlando777, Spongocardo, EzraNehemiah_TF2, and adark

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 7 years ago

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.

0
You have an unneeded ) for the active() end, your tick setup doesn't even work. Tried printing to see when it gets stuck, and it's definitely the tick. Thanks for trying. Orlando777 315 — 7y
0
Nvm, did it myself. Orlando777 315 — 7y
Ad