This is awesome to see. Of course, this means some work for me, but it’s overall a good thing.
This is my implementation before this update:
local userInputService = game:GetService("UserInputService")
local InputTypeChangedRE = game.Workspace.RemoteEventsFolder.Inputs.InputTypeChanged
local mouseInputType =
{
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.MouseWheel
}
local mobileInputType = Enum.UserInputType.Touch
local XboxControllerInputsList = {
Enum.KeyCode.Thumbstick1,
Enum.KeyCode.Thumbstick2,
Enum.KeyCode.ButtonA,
Enum.KeyCode.ButtonB,
Enum.KeyCode.ButtonX,
Enum.KeyCode.ButtonY,
Enum.KeyCode.ButtonL1,
Enum.KeyCode.ButtonL2,
Enum.KeyCode.ButtonL3,
Enum.KeyCode.ButtonR1,
Enum.KeyCode.ButtonR2,
Enum.KeyCode.ButtonR3,
Enum.KeyCode.ButtonStart,
Enum.KeyCode.ButtonSelect,
Enum.KeyCode.DPadUp,
Enum.KeyCode.DPadDown,
Enum.KeyCode.DPadLeft,
Enum.KeyCode.DPadRight,
}
local PS4ControllerInputs = {
}
-- "PS4Controller"
local UserInputTypeSystemModule = {}
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse" --keyboard mouse is default
userInputService.InputBegan:Connect(function(input)
-- print("InputType Test: "..inputTypeThePlayerIsUsing)
-- Computer Input / Keyboard & Mouse: --
if input.UserInputType == Enum.UserInputType.Keyboard then -- Keyboard inputs --
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Xbox" or UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Mobile" then
print("New InputType detected: Keyboard and Mouse")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
userInputService.MouseIconEnabled = true
script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
return
end
end
for i, mouseInputs in pairs (mouseInputType) do -- Mouse inputs --
if input.UserInputType == mouseInputs then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "KeyboardAndMouse" then
print("New InputType detected: Keyboard and Mouse")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
userInputService.MouseIconEnabled = true
script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
return
end
end
end
-- Xbox Input: --
if input.UserInputType == Enum.UserInputType.Gamepad1 then -- Gamepad Inputs --
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Xbox" then -- if the inputType isn't already xbox, make it.
print("New InputType detected: Xbox")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Xbox"
InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
userInputService.MouseIconEnabled = false
script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
return
end
end
for i, xboxInputs in pairs (XboxControllerInputsList) do -- Controller button inputs --
if input.UserInputType == xboxInputs then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Xbox" then
print("New InputType detected: Xbox")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Xbox"
InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
userInputService.MouseIconEnabled = false
script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
return
end
end
end
-- Mobile Input / Touchscreen input: --
if input.UserInputType == Enum.UserInputType.Touch then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Mobile" then -- if not mobile/touch input already, make it.
print("New InputType detected: Mobile")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Mobile"
InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = true
local JumpButton_Path = script.Parent.TouchGui.TouchControlFrame:WaitForChild("JumpButton")
JumpButton_Path.Position = UDim2.fromScale(0.845, 0.715)
--JumpButton_Path.Size = UDim2.new(JumpButton_Path.Size.X*1.2,JumpButton_Path.Size.Y*1.2)
local ToggleMobileButton_RemoteEvent = game.Workspace.RemoteEventsFolder.UI.ToggleMobileButtons
ToggleMobileButton_RemoteEvent.OnClientEvent:Connect(function(whatButtonShouldBeToggled,toggleState)
if whatButtonShouldBeToggled == "JumpButton" then
if toggleState == false then
JumpButton_Path.Visible = false
print("Mobile Jump button toggled OFF")
elseif toggleState == true then
JumpButton_Path.Visible = true
print("Mobile Jump button toggled ON")
end
end
end)
return
end
end
-- PS4 Inputs:
end)
return UserInputTypeSystemModule
local InputTypeChangedRE = game.Workspace.RemoteEventsFolder.Inputs.InputTypeChanged
InputTypeChangedRE.OnServerEvent:Connect(function(player,whatInputTypeIsThePlayerUsing)
if whatInputTypeIsThePlayerUsing == "KeyboardAndMouse" then
script.Parent.XboxInput.Visible = false
script.Parent.KeyboardsInput.Visible = true
script.Parent.mobileInput.Visible = false
elseif whatInputTypeIsThePlayerUsing == "Xbox" then
script.Parent.XboxInput.Visible = true
script.Parent.KeyboardsInput.Visible = false
script.Parent.mobileInput.Visible = false
elseif whatInputTypeIsThePlayerUsing == "Mobile" then
script.Parent.XboxInput.Visible = false
script.Parent.KeyboardsInput.Visible = false
script.Parent.mobileInput.Visible = true
end
end)
There are probably some bad practices throughout the code, but it worked. With PS4 coming, I wondered how I’d show the correct inputs to players. I’ll make another reply here after my implementation of the updated system to share my feedback on it.
I’d like to make a local multiplayer party game sometime in the future, one that requires multiple controllers. That’s after I finish my current project though, so I don’t know what the local multiplayer game would look like. It’s only an idea really.