local UserInputService = game:GetService("UserInputService")
local Touch = Enum.UserInputType.Touch
local Touchscreen = false
local function ToggleMouse(lastInputType)
if lastInputType == Touch then
Touchscreen = true
else
Touchscreen = false
return
end
This is the formatted code so it is easier to read.
Actually I think what you said is correct actually I just don’t have access to my computer anymore and I’ll try it out but for now I’ll mark your post as solution.
ok so i got on my computer and this is the code and im unsure why this isnt working i tried what you said but its not activating. it dosnt print anything when using touchscreen but when i use pc it detects last input type
local UserInputService = game:GetService("UserInputService")
local Touch = Enum.UserInputType.Touch
local TouchMode = false
local inputing
local function ToggleMouse(lastInputType)
if lastInputType == Touch then
local TouchMode = true
UserInputService.MouseIconEnabled = false
inputing = "Touch"
print("Touch")
else
local TouchMode = false
print(" Not Touch")
return
end
end
UserInputService.LastInputTypeChanged:Connect(ToggleMouse)
i fixed that now (i know to do that i forgot to do that thanks) but its not activating any of the function. if so it would print either Not touch or touch but it prints none. its acting like that touchscreen isnt acting as a input for it to activate as lastInput
local UserInputService = game:GetService("UserInputService")
local Touch = Enum.UserInputType.Touch
local TouchMode = false
local inputing
local function ToggleMouse(lastInputType)
if lastInputType == Touch then
TouchMode = true
UserInputService.MouseIconEnabled = false
inputing = "Touch"
print("Touch")
else
TouchMode = false
print("Not Touch")
return
end
print("Activated")
end
UserInputService.LastInputTypeChanged:Connect(ToggleMouse)
I don’t think the exact emulator device is relevant.
Could you put a print before the if statements to see if the Event is firing, and also what the lastInputType is?
nothing outputs at the begining of the script at all it only activates when i use anything but touch
local UserInputService = game:GetService("UserInputService")
local Touch = Enum.UserInputType.Touch
local TouchMode = false
local inputing
local function ToggleMouse(lastInputType)
print("Activated")
print(lastInputType)
if lastInputType == Touch then
TouchMode = true
UserInputService.MouseIconEnabled = false
inputing = "Touch"
print("Touch")
else
TouchMode = false
print("Not Touch")
return
end
end
UserInputService.LastInputTypeChanged:Connect(ToggleMouse)
After further testing, I’ve come to the conclusion that your definition of LastInputType is a bit wrong. UserInputService.LastInputTypeChanged is used to detect when the LastInputType has changed.
So say on PC, there’s a lot of buttons, meaning there’s a lot of different InputType’s.
This means unless your user has a touchscreen laptop, the only InputType on a mobile device is Enum.UserInputType.Touch.
If you could give us the use case of why are you are doing LastInputTypeChanged, maybe we can come up with an alternate solution.
I’m doing it so I make mobile support for my car chassis and for reasons I need to use a if statement in a renderstep wich dose have its problems but I need to use it for performance. So later on I can also use the touch input detection to add their buttons on their screens. They don’t really say that about touched inside last input type. I would think it would be a universal parameter for all devices for compatibility and lessen code.
Would this mean that I need a alternative method for doing mobile support on my vehicle.
I know methods like touch enabled isn’t a good way of detecting if touchscreen is being used for example on pc because someone could have a mouse and keyboard. I’ve seen people use mouse and keyboard on a android device also so I’m trying to do a universal solution to solve my problem.
You should still listen for changes in the LastInputType using UserInputService.LastInputTypeChanged considering there exists touchscreen laptops.
Otherwise, you should just do UserInputService:GetLastInputType() to determine the LastInputType.
Personally I’d use ContextActionService as it’s more fit for the job, however if it’s absolutely necessary for it to be connected in RenderStepped, use the above method.
Actually I might use context action service I didn’t know I could of used that I’ll try that out I just think context action survive is difficult because when I tryed unbundling functions it wouldn’t do it and took a hour to get it working. Thanks for the suggestion lol.