So I made this script that shows Guis show up depending on which device you are on. It’s the same Guis, just different sizes to fit the screen. But for some reason, the script wont work. There are no errors in the output, and I’m not sure what is going on. Here is the script:
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
if isConsole == true then
game.StarterGui.Console.Enabled = true
elseif isMobile == true then
game.StarterGui.Mobile.Enabled = true
elseif isDesktop == true then
game.StarterGui.Desktop.Enabled = true
end
One way is to replace all game.StarterGui to script.Parent since you placed your localscript to StarterGui.
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
if isConsole == true then
script.Parent:WaitForChild("Console").Enabled = true
elseif isMobile == true then
script.Parent:WaitForChild("Mobile").Enabled = true
elseif isDesktop == true then
script.Parent:WaitForChild("Desktop").Enabled = true
end
Left a script so you know what I meant.
Another way is to get it from the LocalPlayer’s Gui. (PlayerGui)
Just a simple StarterGui issue, if you reference the LocalPlayer’s Gui then you should be all set
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
if isConsole == true then
PlayerGui:WaitForChild("Console").Enabled = true
elseif isMobile == true then
PlayerGui:WaitForChild("Mobile").Enabled = true
elseif isDesktop == true then
PlayerGui:WaitForChild("Desktop").Enabled = true
end
StarterGui is just what will be on your screen when the game loads. For getting the player’s guis you could do,
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
if isConsole == true then
script.Parent.Console.Enabled = true
elseif isMobile == true then
script.Parent.Mobile.Enabled = true
elseif isDesktop == true then
script.Parent.Desktop.Enabled = true
end
This will only work if the script you are using is parented to StarterGui.
Reference it if you want it in a player GUI, as a localscript.
It can be placed in startergui, starterplayers, and starterpacks
Code:
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
if isConsole == true then
plrGui:WaitForChild("Console").Enabled = true
elseif isMobile == true then
plrGui:WaitForChild("Mobile").Enabled = true
elseif isDesktop == true then
plrGui:WaitForChild("Desktop").Enabled = true
end
So your script works, but I have another problem. I have a script that is supposed to open the shop once you click on the button, but that doesn’t seem to work. Could you help me with that too?
local shopButton = game.StarterGui.Desktop:WaitForChild("ShopButton")
local consoleButton = game.StarterGui.Console:WaitForChild("ShopButton")
local mobileButton = game.StarterGui.Mobile:WaitForChild("ShopButton")
shopButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
consoleButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
mobileButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
There is more to the script but nothing that has anything to do with my problem.
Do not use startergui for referencing because as soon as the game runs, the GUI is added instantly to the PlayerGui and LocalScripts doesn’t load in StarterGuis. It only loads inside the character or player.
Basically, just replace StarterGui with PlayerGui by getting it from the player.
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local shopButton = plrGui.Desktop:WaitForChild("ShopButton")
local consoleButton = plrGui.Console:WaitForChild("ShopButton")
local mobileButton = plrGui.Mobile:WaitForChild("ShopButton")
shopButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
consoleButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
mobileButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
Edit: It only works when you are alone in a server. Once you are in a server with at least 2 people it gets really glitchy. Only one person can use the shop, and when they leave the permissions go to someone else. Sometimes it won’t even close. How would I fix this?
The localscript is in StarterGUI, and the code inside is:
local isMobile = game:GetService('UserInputService').TouchEnabled
local isConsole = game:GetService('UserInputService').GamepadEnabled
local isDesktop = game:GetService('UserInputService').KeyboardEnabled
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
if isConsole == true then
plrGui:WaitForChild("Console").Enabled = true
elseif isMobile == true then
plrGui:WaitForChild("Mobile").Enabled = true
elseif isDesktop == true then
plrGui:WaitForChild("Desktop").Enabled = true
end