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?
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)