How can I make players be able to rev up their minigun without firing a single bullet via alt-mouse/hold right-click using UIS?

Hello There!

Sorry if the title is a bit sloppish, but anyway, I’m trying to find a way to allow player to rev up their minigun without firing a single bullet by pressing alt-mouse (Or hold Right Click in simpler terms) via UIS (UserInputService)? Thanks in Advance.

I’m guessing you want the player to not be able to fire the minigun unless it’s rotating?

local userInputService = game:GetService("UserInputService")

local rotating = false
local holdingMouse = false

local function fire()
    -- Fire bullet
end

local function rotate()
    -- Rotate minigun
end

local function inputBegan(input, processed)
    if processed then return end
    
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        holdingMouse = true
        
        if rotating then
            repeat
                fire()
                
                task.wait(0.01) -- Interval between each shot
            until not holdingMouse or not rotating
        end
    elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
        rotating = true
        
        repeat
            rotate()
            
            task.wait() -- Interval between each rotation
        until not rotating
    end
end
local function inputEnded(input, processed)
    if processed then return end
    
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        holdingMouse = false
    elseif input.UserInputType == Enum.UserInputType.MouseButton2
        rotating = false
    end
end

userInputService.InputBegan:Connect(inputBegan)
userInputService.InputEnded:Connect(inputEnded)
1 Like

Somewhat, but what I mean is that I want both the Right and Left Mouse Button to roll the barrel, although I only want the left mouse button to fire the gun.

Just add more UIS for the left mouse button to start rotation and a debounce for the right mouse button?

I don’t get what you mean by that?

Lemme give you a code excerpt real quick

local CAS = game:GetService("ContextActionService")

local rotating = false
local holdingMouse = false

local function fire()
    --You know, your function to fire bullets
end

local function rotate()
    while true do
        minigun.barrel.CFrame *= CFrame.Angles(math.rad(1), 0, 0) -- rotation, probably not effective, just off the top of my head
    end
end

-- From Fizzy in his post above
local function inputBegan(input, processed)
    if processed then return end
    
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        holdingMouse = true
        
        if rotating then
            repeat
                fire()
                
                task.wait(0.01) -- Interval between each shot
            until not holdingMouse or not rotating
        else
            repeat
                --os.clock to wait 3 seconds then start firing maybe?
                rotating = true
            until not holdingMouse or rotating
        end
    elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
        rotating = true
        
        repeat
            rotate()
            
            task.wait() -- Interval between each rotation
        until not rotating
    end
end

CAS:BindAction("revFire", inputBegan, false, Enum.UserInputType.MouseButton1)
CAS:BindAction("rev", inputBegan, false, Enum.UserInputType.MouseButton2)

Hmm, I’ll try this. Oh and by the way, from the example, how can I disable RevFiring and Rev functions once the Right/Left Mouse Button is released?

CAS:UnbindAction(ActionName)

Might have to make a few tweaks to the code for it to work, but thats basically the algorithm

I guess I do, because idk if I wrote the code incorrectly but it seems it didn’t work.

Can I see the tree of your minigun? Like in explorer?

I have a model of the gun, although it’s probably the old version of the gun if I remember correctly.

Here’s the minigun:
Prevamped Minigun / Configure (roblox.com)

I cannot view the minigun, looks like it is privated, can you just send me a screenshot in roblox studio?

Huh? I thought I made it public.

I want to ask for some clarification, are you trying to achieve it where the player has to hold down the left mouse button and it will have about 2 seconds of the motor revving up to right speed and upon letting go itll slow back down but only when its going fast enough it will start shooting?

I don’t get what you’re saying.