I'm trying to make a weapon with which you keep left click until there are no more bullets.
For do that, I have a LocalScript in my gun where I have a variable called "hold"
local hold = false
Below I have the following code
tool.Equipped:Connect(function(mouse) gungui:Clone().Parent = player.PlayerGui encontrarCuerpo() equipar:FireServer(tool.Disparar) mouse.Button1Down:Connect(function() if balas.Value <= 0 or reload2 == true then --Nothing happens else hold = true while hold do wait(2) local head = game.Workspace[player.Name].Head.CFrame.lookVector local mouse = CFrame.new(game.Workspace[player.Name].Head.Position, mouse.Hit.p).lookVector difference = (head-mouse) local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p - tool.Handle.CFrame.p).unit*300) local part, position = game.Workspace:FindPartOnRay(ray, player.Character,false,true) if difference.magnitude < 1.33 then if reloading == false then shootevent:FireServer(tool, position, part) balas.Value = balas.Value -1 hold = false end end end end end)
I have a wait of 2 sec and when I press left click instantaneously roblox stops working without wait the 2 sec.
Thanks for read.
That is quite a simple fix. First the reason why your studio crashes is because if you add a infinite loop like that with no yielding it just destroys it. I can't get too into depth but you get the point. If you want it to work faster and not crash then you can do "wait()" rather than "wait(2)"