Detecting what device people are on

Hi Is there anybody out there that can help me fix this script?

local UserInputService = game:GetService("UserInputService")

local lastInput = UserInputService:GetLastInputType()

if (lastInput == Enum.UserInputType.Keyboard) then
	script.Parent.Device.Image = "rbxassetid://6980134429"
elseif (lastInput == Enum.UserInputType.Touch) then
	script.Parent.Device.Image = "rbxassetid://6980136045"
elseif (lastInput == Enum.UserInputType.Gamepad1) then
	script.Parent.Device.Image = "rbxassetid://6980135159"
end

The script somewhat works but only for PC/Keyboard i have also tried changing keyboard to mouse but still ended up with the same results.

Appreciate any help!

I tested your code

local UserInputService = game:GetService("UserInputService")

local lastInput = UserInputService:GetLastInputType()
print("test",lastInput)
if (lastInput == Enum.UserInputType.Keyboard) then
	print("PC")
elseif (lastInput == Enum.UserInputType.Touch) then
	print("Mobile")
elseif (lastInput == Enum.UserInputType.Gamepad1) then
	print("Xbox")
end

although the first if statement didn’t work because LastInput was always Enum.UserInputType.MouseMovement for me on PC when I tested on mobile

It seemed to work… Heres an example of how I detect device just modified code I found on scriptinghelpers

ignore the comments wasn’t for this response