so I want the game to check what device the player has. If its on a mobile device then the gui will pop up. If not then the gui will NOT pop up. Is there a way to do that?
Help! I want to make sure a divice is mobile in my game! how do i do it?
1 answer
The best way to check if a device is on mobile is to check if the screen can be touched using UserInputService with the TouchEnabled property.
Here's an example of making the Parent object visible when the device is on mobile:
if game:GetService("UserInputService").TouchEnabled then
script.Parent.Visible = true
end
Edit #1: If you don't want touch screen computers to use this, then also check if KeyboardEnabled is false, like in this example:
local UIS = game:GetService("UserInputService")
if UIS.TouchEnabled and not UIS.KeyboardEnabled then -- If there's a touch screen with no keyboard then....
script.Parent.Visible = true
end
Edit #2: If you have a server script (not a local script), then I'd use a RemoteFunction. The issues I've had with RemoteFunctions is that you need a certain type of function. This example records what device everyone is using to the server when the player joins:
-- Server (Non-local script)
local isOnMobile = {}
local event = Instance.new("RemoteFunction", game:GetService("ReplicatedStorage"))
event.Name = "MobileData" -- Change event name if you have other events.
game:GetService("Players").PlayerAdded:Connect(function(p)
local isMobile = event:InvokeClient(p)
if p and isMobile ~= nil then -- Alot of issues happen with RemoteEvents/RemoteFunctions. Good to check this stuff.
isOnMobile[p.UserId] = isMobile
end
end)
-- Client (Local script)
game:GetService("ReplicatedStorage"):WaitForChild("MobileData").OnClientInvoke:Connect(function()
local isMobile = false
local UIS = game:GetService("UserInputService")
if not UIS.KeyboardEnabled and UIS.TouchEnabled then
isMobile = true
end
return isMobile
end)
19 comments
thank you.
That won't do what OP wants. This is true if the user has a touch screen computer.
?
You can also check if the user doesn't have a keyboard if you want that too. I'll edit this to have KeyboardEnabled
wait really!? becase for my game i dont want my buttons to appear both on mobile and PC to prevent auto clicking... so this answer is...... wrong?
I edited the post with it also checking KeyboardEnabled. If you don't want double clicking, you should be fine using else if there's any exception.
yea i eddited it to in my script.wait THIS is a script right? not a local script?
Also not UIS.KeyboardEnabled is similar to UIS.KeyboardEnabled == false, it is just less likely to error this way.
Only works with local scripts. I'd use a RemoteFunction to get what property each player has if you're using a server script.
hmm ok
I'll edit this to add another example with a server script.
Updated post
If anyone can't read line 14: game:GetService("ReplicatedStorage"):WaitForChild("MobileData").OnClientInvoke:Connect(function()
note:My game is not experimential mode and not filtering enabled
all of all thoes edits which is totaly the best one.edit 2 or 1,3
Still should be okay
"not experimential mode and not filtering enabled" both of these are the opposite, what do you mean?
Line 14 will error.
Also, the parent argument is deprecated, do not give OP deprecated code.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Yes, there is a way. Good day.
...
What? Your question is a yes or no question, and the answer will be a yes or no answer.
yea i guess......