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

How i can fix this automatic rifle script?

Hi guys!

Sorry for bad english.. i have write this code ->

	UIS.InputBegan:connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if Equipado == true then
				if Recarregando == false then
					Atirando = true
					spawn(function()
						while Atirando == true do
						wait()
							if Recarregando == false then
								if Bala > 0 then
									Atacar()
									Bala = Bala - 1
									refresh(Bala)
								elseif Recarregando == false then
									Recarregando = true
									script.Parent.Handle.Reload:Play()
									refresh("R")
									Atirando = false
									wait(2)
									Bala = LimitBala
									refresh(Bala)
									Recarregando = false
								end
							end	
						end
					end)
				end
			end
		end
	end)
	UIS.InputEnded:connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if Equipado == true then
				Atirando = false
			end
		end
	end)

This script work correctly, but if i do a double-click, this script broke (in short, the script is performed 2 times and not 1).

Who can help me?

1 comment

0

Obviusly, ONLY if is a fast double-click. If is a slow double click all works good

1 answer

Fixed:

UIS.InputBegan:Connect(function(Input)

    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
       keydown = true
    end
end)

UIS.InputEnded:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
        keydown = false
    end
end)

while true do
	wait(0.03)
	if keydown then
		if Equipado == true then
			if Recarregando == false then
				Atirando = true
				if Bala > 0 then
					Atacar()
					Bala = Bala - 1
					refresh(Bala)
				elseif Recarregando == false then
					Recarregando = true
					script.Parent.Handle.Reload:Play()
					refresh("R")
					Atirando = false
					wait(2)
					Bala = LimitBala
					refresh(Bala)
					Recarregando = false
				end
			end
		end
	end
end

1 comment

0

change with while wait() do, is better

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