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

FPS game framework shooting not working correctly problem?

Alright, so...

I have this problem where the shooting system in my fps is not working. So here is what I have

I do have something that stops shooting when input ended

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(inputObject) -- on input
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then -- MB1
		delay(0,function() -- To stop lag in the framework
			if Automatic == true then
				shoot()
				wait(0.5)
				shoot()
			else
				Shooting = true
				Shooting = false
			end
		end)
	end
end)

and yes before you say it: it should shoot wait 0.5 and shoot again yes. But here's the problem it shoots as fast as the wait() what can I do to fix this.

1 comment

0

connect is deprecated so use Connect

1 answer

✓ Accepted answer
local UIS = game:GetService("UserInputService")
local m, t, f = 0, true, false

UIS.InputBegan:Connect(function(inputObject)
    if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        m = t
    end
end)

UIS.InputEnded:Connect(function(inputObject)
    if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        m = f
    end
end) ---You could remove this part if you want the gun to continue shooting after the player releases the mouse button

while true do
     wait()
     if m and Automatic then
          shoot()
          wait(0.5)
          shoot()
          m = f
     else
          Shooting = true
          Shooting = false
     end
end

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