Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script doesn't detect TouchEnabled?

I'm trying to make a script which shows the player a GUI message depending on whether TouchEnabled is Enabled or Disabled. I've found that if I click 'Play' while in Studio it will work correctly whereas if I load my game on my phone, it does not.

local ServerStorage = game:GetService("ServerStorage")
local Hum = script.Parent
local player = game.Players:GetPlayerFromCharacter(Hum)
local PlayerGUIs = player:WaitForChild("PlayerGui")
local UIS = game:GetService("UserInputService")

if UIS.TouchEnabled then
ServerStorage:FindFirstChild("PossiblyMobile"):Clone().Parent = PlayerGUIs
print("Possibly Mobile")
else
ServerStorage:FindFirstChild("PossiblyNotMobile"):Clone().Parent = PlayerGUIs
print("Possibly Not Mobile")
end

Any idea why it isn't working?

2 comments

0

Is this a local or server script? Because your code is undoubtedly wrong.

0

It’s in a server script located inside ServerScriptService

1 answer

✓ Accepted answer

If you read the wiki page on how to use the UserInputService, it states that the UserInputService can only be used in LocalScripts. If you still want to use the service, you can use a RemoteEvent from client to server.

Your other option is to put the things you're accessing from ServerStorage in ReplicatedStorage, where the client can access them.

3 comments

0

This also applies for the PlayerGuis you are accessing.

0

When I change it to a localscript it doesn't print anything

0

Changed the script up and it now works, thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.