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?
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)
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".