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

Having an issue with press R to reload script, how can I fix it?

Trying to make an FPS game, made a press R to reload script, however, once I reload, every time I shoot, it automatically reloads, even if I've only shot one bullet. Any suggestions on how I can fix it?

userInput.InputBegan:Connect(function(input, gameProcessed)

if not gameProcessed then
	if input.UserInputType == Enum.UserInputType.Keyboard or Enum.UserInputType.Gamepad1 then
		local keycode = input.KeyCode
		if keycode == Enum.KeyCode.R or Enum.KeyCode.ButtonX then
			reload_sound:Play()
			reload_sound.Ended:Wait()
			gun.Ammo.Value = 12
		end
		
	end
end

end)

1 comment

0

It has worked now, thank you for your help!

1 answer

✓ Accepted answer

the or condition will only work if you repeat what's on the other side, otherwise your just repeating a statement and anything will be accepted.

this is your fix:

line 04

if keycode == Enum.KeyCode.R or keycode == Enum.KeyCode.ButtonX then

line 02

if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then

If this fixes your problem, consider accepting it as your answer.

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