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

How do i make the X button work for controller?

Tool.Equipped:connect(function(TempMouse)
	Equipped = true
	if Module.AmmoPerMag ~= math.huge then GUI.Frame.Visible = true end
	GUI.Parent = Player.PlayerGui
	UpdateGUI()
	Handle.EquippedSound:Play()
	if Module.WalkSpeedRedutionEnabled then
	Humanoid.WalkSpeed = Humanoid.WalkSpeed - Module.WalkSpeedRedution
	else
	Humanoid.WalkSpeed = Humanoid.WalkSpeed
	end
	CrosshairModule:setcrosssettings(Module.CrossSize, Module.CrossSpeed, Module.CrossDamper)
	UserInputService.MouseIconEnabled = false
	if EquippedAnim then EquippedAnim:Play(nil,nil,Module.EquippedAnimationSpeed) end
	if IdleAnim then IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed) end
	TempMouse.KeyDown:connect(function(Key)
----------------------IMPORTANT HERE--------------------------------
		if string.lower(Key) == "r" then
			Reload()
		if string.lower(Key) == Enum.KeyCode.ButtonX then
			Reload()
-------------------------------------------------

1 answer

✓ Accepted answer

I believe you're looking for Gamepad-Input

Example Code:

local UserInputService = game:GetService("UserInputService")
 
UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.ButtonX then
			-- Button x pressed
		end
	end
end)

1 comment

0

Thanks so much, made everything much easier in my life. Honestly coding Xbox sucks. If you have the time, is there a way or a source I can read to active controller vibrate if something happens?

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