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

Help With Controller?

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

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