Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

aIs my code a efficient way of doing loops when mousebutton1 is down? To repeat loops

local Player = game.Players.LocalPlayer 
local character =  Player.Character 
local Mouse = Player:GetMouse() 
local debounce = true 
Mouse.Button1Down:Connect(function()
 debounce = false 
 while true do wait() print('gg')
  if debounce == true then return 
  end 
  end 
  end) 
  Mouse.Button1Up:Connect(function() 
  if debounce == false then 
  debounce = true 
  end 
  end)

This is my code and im trying to print when the mouse button is down just like a automatic gun in phantom forces shooting repedeatly im trying to print repedeatly it works but im just wondering if this is how most people do it and if its efficient

1 comment

0

What most people do is they use a boolean that is false, set it to true when the button is being held down and have a loop for while that boolean is true.

1 answer

It's not an inefficient algorithm for shooting. Though, I should note that it would be preferable to use this code within a framework for your game using methods such as OOP in order to match the specifications of each weapon. In addition to that, the debounce would also be specific to each weapon and each would have their own requirements to shoot.

This discussion is preserved as it was. New answers, comments, and votes are closed.