Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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

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. DeceptiveCaster 3761 — 5y

Closed as Primarily Opinion-Based by User#24403

This question has been closed because it is a discussion about a topic focused on diverse opinions, which isn't a good fit for our Q&A format.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
rsublu 0
5 years ago

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.

Ad