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

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

Asked by 3 years 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 — 3y

1 answer

Log in to vote
4
Answered by 3 years ago
Edited 3 years 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