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

FPS game framework shooting not working correctly problem?

Asked by 5 years ago
Edited 5 years ago

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.

0
connect is deprecated so use Connect User#19524 175 — 5y

1 answer

Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
5 years ago
Edited 5 years ago
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
Ad

Answer this question