I used covertcode’s gun tutorial and im trying to make it automatic but when I hold down click nothing happens, no error or anything
repeat until mouse.Button1Up
if cooldown == true then
return
end
if firetype == 2 then
if cammo > 0 then
cooldown = true
pew()
animtrack:Play()
cammo -= 1
wait(cdtime)
cooldown = false
elseif magcount > 0 then
cooldown = true
animtrack3:Play()
wait(reloadtime)
cammo = maxsize
magcount -= 1
cooldown = false
end
game.ReplicatedStorage.ammoupdate:FireServer(cammo, magcount, j, b)
end
end
Edited the code for you a bit
Notes:
You don’t actually need a cooldown variable, as this is a repeat… until loop and wait automatically yields the whole loop
Don’t use return in a loop, it will end the entire script (correct me if im wrong) or the current function. Consider using continue to terminate the current literation of the loop instead
repeat
if firetype == 2 then
if cammo > 0 then
pew()
animtrack:Play()
cammo -= 1
wait(cdtime)
elseif magcount > 0 then
animtrack3:Play()
wait(reloadtime)
cammo = maxsize
magcount -= 1
end
until mouse.Button1Up
(I assume the repeat… until loop is in a function hooked up to MouseButton1Down)
Try this for the hold. (Put it in your local script.):
local UIS = game:GetService("UserInputService")
local LMBHeld = false
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
warn("Input Started.")
LMBHeld = true
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
warn("Input Ended.")
LMBHeld = false
end
end)
while LMBHeld == true do
---Your code here
end
So this code is a function to shoot and so this code is irrelevant, the semi auto shooting works.
so now its
elseif firetype == 2 then
repeat
shoot()
until mouse.Button1Down == false```
But now when I click, the gun keeps shooting after I let go of click, and if I click twice it lags a bunch
the gun only stops when it is out of ammo.