What do you want to achieve?
I want to detect, what the last input was, the player has made.
What is the issue?
I tried the script below and the only thing, that happend, was that it printed, that I had all of the things, since I had a mouse, a controller and a keyboard connected. But I want, that it detects what the last input was, not what things I have connected. (The script is in StarterPlayerScripts)
local UserInputService = game:GetService("UserInputService")
local PlayerGUI = Player.PlayerGui
local lastInput = UserInputService:GetLastInputType()
local function onInputBegan(input)
if UserInputService.GamepadEnabled == true then
print("User has a controller")
end
if UserInputService.KeyboardEnabled == true then
print("User has a keyboard")
end
if UserInputService.TouchEnabled == true then
print("User has a touchscreen")
end
if UserInputService.MouseEnabled == true then
print("User has a mouse")
end
if UserInputService.VREnabled == true then
print("User has a vr headset")
end
end
UserInputService.InputBegan:Connect(onInputBegan)
Output:
I hope you can help me, so I know how I can detect what the last input was.
local UserInputService = game:GetService("UserInputService")
local lastInput = Enum.KeyCode.Unknown
local function onInputBegan(Input)
print("Last input:", lastInput)
print("New input:", Input.KeyCode)
lastInput = Input.KeyCode
end
UserInputService.InputBegan:Connect(onInputBegan)
You have it print if its enabled, doesn’t matter in the code if its the last input or not. You would have to check in the if loop if it is the last input type. You also only update the last input type at first, so it would probably only print the first ever input, but I’m not sure on how GetLastInputType() works.
local UserInputService = game:GetService("UserInputService")
local lastInput = Enum.UserInputType.MouseButton1
local function onInputBegan(Input)
print("Last input:", lastInput)
print("New input:", Input.UserInputType)
lastInput = Input.UserInputType
end
UserInputService.InputBegan:Connect(onInputBegan)