Shouldn't my script be working?

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

And here is a picture of the Guis:
image

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)

2 Likes

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
4 Likes

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.

I actually had this originally, but there was an error message saying something similar to “Desktop does not exist” so I changed it.

And by PlayerGui, would I reference it in the script, or would I put the script into PlayerGui (If it even exists I forget)

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
1 Like

Ok thanks, I’ll be sure to try it out tomorrow. I will let you know how it goes.

No problem, and alright.

Also if it doesn’t work, you can try out my second script in message 6.

1 Like

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.

1 Like

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)

Thanks for the help, your script worked.

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?

Sorry to be a bother, but you haven’t replied in 3 weeks. This is really important for my game, and it would be extremely helpful if you replied.

I’m confused why that occurred since that isn’t supposed to happen. Well maybe set the localscript to the GUI?

If that doesn’t work, give more details about the localscript so I can try finding the problem.

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

Hey, sorry to bother you. The problem still hasn’t been fixed, and it would be great if you helped me.