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

Help With Controller?

Asked by
Scootakip 299 Moderation Voter
8 years ago

Trying to get a script for controllers working to reload the gun in my game.

This is the working script that reloads when you press R on the keyboard

function Reload(key)
    key = key:lower()
    if key == 'r' then
        if enabled == true and Gun.Ammo.Value < MaxAmmo and script.Parent.CanReload.Value == true then
            LoadSound:Play()
            wait(LoadSound.TimeLength)
            Gun.Ammo.Value = MaxAmmo
        end
    end
end

This is the broken script that doesn't work when you press X on the gamepad

function ReloadController(controller)
    game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Gamepad1 then
        if input.KeyCode == Enum.KeyCode.ButtonX then
            if enabled == true and Gun.Ammo.Value < MaxAmmo and script.Parent.CanReload.Value == true then
                LoadSound:Play()
                wait(LoadSound.TimeLength)
                Gun.Ammo.Value = MaxAmmo
            end
        end
    end
end)
end

1 answer

Log in to vote
0
Answered by 8 years ago

On the second block of code, you didn't close the function(input on line 2.

0
Yeah I did. Look over the script Scootakip 299 — 8y
Ad

Answer this question