wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 30 Mar 2016 11:41 PM |
So I've been trying to make a script that will make a certain GUI visible when a user is using a mobile device. I'm new to scripting and I got really confused and I need help... This is literally my second script that I attempted to write so don't be harsh
if game:GetService("UserInputService").TouchEnabled == false then script.Player.PlayerGui:FindFirstChild("GUI") script.Parent.GUI.Visible = true end
|
|
|
| Report Abuse |
|
|
|
| 30 Mar 2016 11:47 PM |
if game:GetService("UserInputService").TouchEnabled == false then script.Player.PlayerGui:FindFirstChild("GUI") script.Parent.GUI.Visible = true end You set the conditional on the first line to false, meaning if the actual user is on a mobile device, this won't activate. You need to make .TouchEnabled == true |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 31 Mar 2016 12:44 AM |
| @NOTlaedere Yea, I know. I set it to false so that it would show up on the PC because I couldn't use my mobile device at that moment. If it showed up on PC then it would've meant that it works. However it didn't... |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 01:33 AM |
The third line in your script should have been: script.Parent.PlayerGui.GUI.Visible = true
If that change is not enough to fix it, then I suspect that the script is running before all of the referenced objects are loaded. Try the following, and check the output.
function waitForChild(instance, name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end return instance:FindFirstChild(name) end
if game:GetService("UserInputService").TouchEnabled == false then --(or true) print("check 1") waitForChild(script.Player,"PlayerGui") print("check 2") waitForChild(script.Player.PlayerGui,"GUI") print("check 3") script.Parent.GUI.Visible = true print("check 4") end
|
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
| |
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 31 Mar 2016 01:30 PM |
| @Time that doesn't seem to work. |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 31 Mar 2016 02:38 PM |
| I tried other ways but it still doesn't work.... |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
| |
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
| |
|
Darkenus
|
  |
| Joined: 17 Jul 2014 |
| Total Posts: 1997 |
|
|
| 31 Mar 2016 11:34 PM |
is this a local script or normal script? and where is this script located? |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 31 Mar 2016 11:36 PM |
| This is a normal script located in workspace |
|
|
| Report Abuse |
|
|
Darkenus
|
  |
| Joined: 17 Jul 2014 |
| Total Posts: 1997 |
|
|
| 31 Mar 2016 11:46 PM |
So you want to get the InputService of the server?
The server has no input.
Therefore you NEED to put this in a localscript - somewhere in StarterGui, StarterPack, or StarterPlayerScripts > PlayerScripts.
You're trying to get the input of a PLAYER, not the server.
http://wiki.roblox.com/?title=API:Class/UserInputService
The UserInputService is a service which is used to detect the type of input available on a user's device via the use of a LocalScript. It allows LocalScripts to perform different actions depending on the device used to provide the best experience for the end user. The purpose of this service is primarily to allow for games to work well on both mobile devices and computers.
> LOCALSCRIPT! |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 31 Mar 2016 11:58 PM |
| I made it a localscript and put it in StarterGui, it's still not working. |
|
|
| Report Abuse |
|
|
wayne2018
|
  |
| Joined: 04 Jun 2014 |
| Total Posts: 2509 |
|
|
| 01 Apr 2016 12:10 AM |
| I figured it out! It finally works! |
|
|
| Report Abuse |
|
|
| |
|