I have an Xbox Controller using a MacBook pro. It works if I open a game, I can run, jump, and move the camera.
Is the following the only way to test the code I write for the controller?
Write my code in a local script for the controller.
Save and publish the game to Roblox
Play the game on Roblox and check the dev console to check output statements.
This process is the only one I have found that produces the correct output. If there is a method to test within Studio I would be greatly appreciative if you could let me know.
Cheers.
From what I understood reading the description, it seems that you would like to know how you can print any keys on your Xbox controller to see if it is working. It is actually possible to do so!
Firstly, you can create by getting the players once added and see in what device they are using with UserInputService. For instance, let’s say you would like to know if someone is on Xbox, you would have to create a LocalScript and do the following:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local function DetectDevice()
if UserInputService.GamepadEnabled then
return "Console"
end
ed
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " is playing on " .. DetectDevice())
end)
In case of knowing the player pressed a key, you would have to create an if statement while using two parameters, input and gameProcessed. Furthermore, we can apply the same methodology of being in a LocalScript, but let’s put in StarterPlayer > StarterPlayerScripts + getting another function, Player, which is basically getting the local player once joining the experience:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(player, input, gameProcessed)
if gameProcessed then return end
print(input.KeyCode)
if input.KeyCode == Enum.KeyCode.A then
print(player.Name .. " touched the key A!")
end
end)
I already have my code written to recognize the controller. It works, but only if I publish the game on Roblox, then play the game on Roblox and open the Dev Console, press buttons and see the output while playing the game.
I want to know, can I generate the test output messages in Studio, or the studio test server without having to publish, play, and open the dev console which is time consuming and annoying.