Ad
Log in to vote
0

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

Asked by 26 days ago

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)

0
It has worked now, thank you for your help! NuggetHasJoined 7 — 26d

1 answer

Log in to vote
4
Answered by 26 days ago
Edited 26 days ago

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.

Ad

Answer this question