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

I'm having a bit of a problem with these guns, how do I fix them?

Asked by 7 years ago
Edited 7 years ago

I'm quite inexperienced at coding, but I wanted to try modifying some existing gun scripts. I tried to keybind the guns to Q, another method I tried resulted in the guns dropping out of the aim stance any time I pressed any other button.

The original script was like this:



mouse.Button2Down:connect(function() if not meleeing and not reloading then aim:Play() aiming = true tool.GripForward = Vector3.new(-0.1, 0, -0.9) tool.GripRight = Vector3.new(0.9, 0, -0.1) mouse.Button2Up:connect(function() aiming = false aim:Stop() tool.GripForward = Vector3.new(0, 0, -1) tool.GripRight = Vector3.new(1, 0, 0) end) end end)

The first thing I tried was this:


`mouse.KeyDown:connect(function(key) if key == "q" and not meleeing and not reloading then aim:Play() aiming = true tool.GripForward = Vector3.new(-0.1, 0, -0.9) tool.GripRight = Vector3.new(0.9, 0, -0.1) mouse.KeyDown:connect(function() aiming = false aim:Stop() tool.GripForward = Vector3.new(0, 0, -1) tool.GripRight = Vector3.new(1, 0, 0) end) end end)

and here's what I did most recently :

`mouse.KeyDown:connect(function(key)
        if key == "q" and not meleeing and not reloading then
            aim:Play()
            aiming = true
            tool.GripForward = Vector3.new(-0.1, 0, -0.9)
            tool.GripRight = Vector3.new(0.9, 0, -0.1)
                mouse.KeyDown:connect(function()
                if key == "q" and aiming then 
                aiming = false
                aim:Stop()
                tool.GripForward = Vector3.new(0, 0, -1)
                tool.GripRight = Vector3.new(1, 0, 0)
            end)
        end
    end)
`

But I got an error that said: Expected identifier, got ')' when I tried the most recent method how do I correct this error?

0
Your umm use is a bit messed up with the uhh code blocks and stuff, mind fixing that? Abstract_Life 65 — 7y

2 answers

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
7 years ago
Edited 7 years ago

Not sure if this is what you want but I edited my answer.

mouse.KeyDown:connect(function(key) --Function for when you press 'q'
    if key == "q" and not meleeing and not reloading then
        aim:Play()
        aiming = true
        tool.GripForward = Vector3.new(-0.1, 0, -0.9)
        tool.GripRight = Vector3.new(0.9, 0, -0.1)
    end
end)

mouse.KeyUp:connect(function(key) --Function for when you let go of 'q'
    if key == "q" and aiming then 
        aiming = false
        aim:Stop()
        tool.GripForward = Vector3.new(0, 0, -1)
        tool.GripRight = Vector3.new(1, 0, 0)
    end
end)
0
That helped to an extent, but what I wanted to do was make it so the guns don't go back into resting position until you press Q again. How do I do this? termanator990 5 — 7y
0
Woops, sorry I forgot the code block. And I am not sure. FiredDusk 1466 — 7y
0
I edited my answer. FiredDusk 1466 — 7y
Ad
Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

This is the important error:

mouse.KeyDown:connect(function()
                if key == "q" and aiming then

you did not put a "key" parameter inside the function() parentheses. So, it uses the key variable that you already defined long before, which will always be "q".

Answer this question