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

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

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?

1 comment

0

Your umm use is a bit messed up with the uhh code blocks and stuff, mind fixing that?

2 answers

✓ Accepted answer

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)

3 comments

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?

0

Woops, sorry I forgot the code block. And I am not sure.

0

I edited my answer.

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

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