Adding ps4-ps5 support to my gun system

Hello, i am currently trying to add ps5 support to my gun system, however for some reason the gun wont shoot or aim even if the buttons are pressed

if ((Device == "Console" and UserInputService:IsGamepadButtonDown(Enum.KeyCode.ButtonL2)) or (Device == "Desktop" and UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2))) then

Some help would be apreciated, i heard isgamepadbuttondown isnt enabled, but the post was from 2018.

The “Device” variable is a value in replicated storage, it can be Console, Desktop or Mobile, i detect it like this:

function GetPlatform()
	if (GuiService:IsTenFootInterface()) then
		return "Console"
	elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then
		return "Mobile"
	else
		return "Desktop"
	end
end

ReplicatedStorage:WaitForChild("Device").Value = GetPlatform()

Hey szl,

It looks like you’re on the right track! For PS5 support, try using UserInputService.GamepadEnabled to detect if a gamepad is connected. Also, ensure you’re using UserInputService.InputBegan and InputEnded to handle gamepad button presses.

if Device == "Console" and UserInputService.GamepadEnabled then
    UserInputService.InputBegan:Connect(function(input, gameProcessed)
        if input.KeyCode == Enum.KeyCode.ButtonR2 then
            -- Handle aiming/shooting here
        end
    end)
end

This should help in detecting the gamepad buttons correctly.

The thing is i handle my firing aiming and reloading all inside a runservice loop… Is there not a way to actively detect while in the loop like IsKeyDown(ButtonL)

Of course! You can still detect the gamepad buttons inside a RunService loop. Try using UserInputService:IsGamepadButtonDown within your loop:

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

function GetPlatform()
    if GuiService:IsTenFootInterface() then
        return "Console"
    elseif UserInputService.TouchEnabled and not UserInputService.MouseEnabled then
        return "Mobile"
    else
        return "Desktop"
    end
end

ReplicatedStorage:WaitForChild("Device").Value = GetPlatform()

RunService.RenderStepped:Connect(function()
    local Device = ReplicatedStorage:WaitForChild("Device").Value
    if Device == "Console" and UserInputService.GamepadEnabled then
        if UserInputService:IsGamepadButtonDown(Enum.KeyCode.ButtonL2) then
            -- Handle aiming/shooting here
        end
    elseif Device == "Desktop" then
        if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
            -- Handle aiming/shooting here
        end
    end
end)

This way, the gamepad buttons will be checked continuously within the RenderStepped loop.

This doesn’t work gsdgsgsgsgsgssg