I am trying to make a script so that if someone is on mobile the GUI above their head will say “mobile” and it always thinks I am on PC or have keyboard enabled. I am quite new to scripting so it may just be a rookie error, if you need any other information/screenshots I will see if I can get them for you.
This is my script:
local UserInputService = game:GetService("UserInputService")
local mobile = UserInputService.TouchEnabled
local touchscreen = UserInputService.KeyboardEnabled and UserInputService.TouchEnabled
if mobile == true then
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if char:FindFirstChild("Head") and player then
local clone = script.GUI:Clone()
clone.Parent = char:FindFirstChild("Head")
-----------------------------------------
clone.TextLabel.Text = "Mobile"
clone.TextLabel.TextColor3 = Color3.fromRGB(53, 107, 165)
end
end)
end)
elseif touchscreen == true then
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if char:FindFirstChild("Head") and player then
local clone = script.GUI:Clone()
clone.Parent = char:FindFirstChild("Head")
-----------------------------------------
clone.TextLabel.Text = " "
clone.TextLabel.TextColor3 = Color3.fromRGB(165, 22, 146)
end
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if char:FindFirstChild("Head") and player then
local clone = script.Name:Clone()
clone.Parent = char:FindFirstChild("Head")
-----------------------------------------
clone.TextLabel.Text = player.name
clone.TextLabel.TextColor3 = Color3.fromRGB(165, 0, 0)
end
end)
end)
end
The images are of what it looks like on mobile and the script with the GUIs in.
