I am so sick and tired of joining a game and getting console controls because I have a controller plugged in.
If you have half a brain, you should be using LastInputTypeChanged() or GetLastInputType().
I made this small module for myself, specifically tackling cross-device development. I implore you to either use this, a module like it, or make it yourself. I do not want controller controls when I join Roblox games anymore.
Example usage:
Obviously, this code snippet is missing some context, but what it does is change keybind on UI. You can see how .DeviceUpdated is used to dynamically update the label every time the user’s device is changed. In addition, we can get the user’s device by simply calling GetUserDevice(), that way we know what to render for each type of device.
local function updateLabel()
local device = UserDevice.GetUserDevice()
local iconType = "Image"
if device == "Controller" then
template.ImageLabel.Image = UserInputService:GetImageForKeyCode(keybind.Controller[1])
elseif device == "PC" then
if keybind.PC[1] == Enum.UserInputType.MouseButton1 then
template.ImageLabel.Image = "rbxassetid://94107535658418"
else
template.ButtonText.Text = utf8.char(keybind.PC[1].Value):upper()
iconType = "Text"
end
end
template.ButtonText.Visible = iconType == "Text"
template.ImageLabel.Visible = iconType == "Image"
template.Visible = device ~= "Mobile"
end
UserDevice.DeviceUpdated:Connect(updateLabel)
updateLabel()