My local script won't enable the gui. PlayerGUI is referenced and I'm stumped

This issue is seen in the video. I have a test script setup to enable the gui. I know there’s multiple lines for the same thing but that’s me trying to fix this bug. The script detects its disabled and the input but it doesn’t enable the gui. The local script is in starterscripts and if I run the command through the command bar it works fine.

Any ideas would be great. It used to work no problem until I did a tooltip that detected the shift input. But even with that disabled it still doesn’t work. Again, thank you

Player = game:GetService("Players").LocalPlayer
UserInputService = game:GetService("UserInputService")
QuestBookToggle = Player.PlayerGui.QuestBook

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.L then
		if QuestBookToggle.Enabled == false then
			

			--[[print("ITS OFF") 
			Player.PlayerGui.QuestBook.Enabled = true
			game.Players.gbcooper.PlayerGui.QuestBook.Enabled = true]]

			QuestBookToggle.Enabled = true
		else
			QuestBookToggle.Enabled = false
		end
	end
end)

The script in case it was too quick in the video.

Hi!

If I’m not wrong, GUIs in PlayerGUI may not load as quick as the script starts running.

Change
QuestBookToggle = Player.PlayerGui.QuestBook
To
QuestBookToggle = Player.PlayerGui:WaitForChild(“Questbook”)

I did try that. Nothing unfortunately. I even changed it to update the variable when the button is pressed. IE

Player = game:GetService("Players").LocalPlayer
UserInputService = game:GetService("UserInputService")
QuestBookToggle = Player.PlayerGui.QuestBook

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.L then
		
		QuestBookToggle = Player.PlayerGui.QuestBook

		if QuestBookToggle.Enabled == false then
			
			--[[
			print("ITS OFF")
			Player.PlayerGui.QuestBook.Enabled = true
			game.Players.gbcooper.PlayerGui.QuestBook.Enabled = true
			]]
			
			QuestBookToggle.Enabled = true
		else
			QuestBookToggle.Enabled = false
		end
	end
end)

I have checked that everything is loaded. It is. If I set another gui element to enable it, it will no problem.

Could you provide an explorer with your playergui


Here’s everything loading up to ensure its all setup.

I have some ideas, but first:

this works fine, but instead of doing this you can simplify it to one line like so:

QuestBookToggle.Enabled = not QuestBookToggle.Enabled

just something I noticed that might be useful to you.


Any who I dont exactly think the error has to do with the UI, my guess is that it probably involves the script not actually getting to the point where it should enable the UI.

To test this you can use break points so it stops when it reaches where you change the enabled property, or you can make a print statement to print the enabled property.

Also just to be sure whilst youre in the playtest, go to your playergui and see if the guis Enabled property is changing or not, just to be sure.

I will simplify. Thanks for the pointer. This is it more print outputs and checking the enable.

task.wait(4) --or 3 .. will never even notice this

Player = game:GetService("Players").LocalPlayer
UserInputService = game:GetService("UserInputService")
QuestBookToggle = Player:WaitForChild("PlayerGui")
	:WaitForChild("QuestBook")
--
--

Let’s see it get out of that.

this is the debug script used

Player = game:GetService("Players").LocalPlayer
UserInputService = game:GetService("UserInputService")
QuestBookToggle = Player.PlayerGui.QuestBook

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.L then
		
		QuestBookToggle = Player.PlayerGui.QuestBook

		if QuestBookToggle.Enabled == false then
			
			print("ITS OFF")
			--[[
			Player.PlayerGui.QuestBook.Enabled = true
			game.Players.gbcooper.PlayerGui.QuestBook.Enabled = true
			]]
			
			QuestBookToggle.Enabled = true
			print("ITS ON")
		else
			QuestBookToggle.Enabled = false
			print("ITS OFF")		
			
		end
	end
end)

This actually did work although its not too elegant. Is PlayerGui taking too long to load? I figured it setting the variable with each input would be fine.

Also why is it still going through all the if statements if its not enabled?

It’s a thing of beauty. For sure lock on and the time at the top is nothing vs load and ready to use it.
I do this anyways if it can wait for a moment without bothering, just to help the load move faster.
3 is a given, will not even be fully loaded and ready to go before that is burnt up.. 4 is asking for a moment.

As evident by your debug script, .InputBegan is firing twice, causing your ScreenGui to be disabled immediately after being enabled.

First, make sure you don’t have a duplicate script running somewhere with the same code.
If that’s not the case, then figure out why this event is firing twice. It may just be the way the engine works and you need to filter out one of the events, or add a debounce, or listen to input with a different API.

It loads the character manually so I set it to fire a remote event when the player has loaded and then the local script listens and kicks off. Does this seem reasonable?

That way if the server lags past the set seconds its not gonna error and if it loads quicker than its good to good. The logic seems right I think

I’ve done that too, in a way.. Have a loading screen set up that fades in and out, but waits for a bool to be set before fading into the game. Little bit of smoke to help a terrain generator seem to to blend right in.

That was my solution if the event didn’t work haha. I was just gonna fade black. But since theres pvp in the game I thought it might put someone at a disadvantage while they’re loading in.

Thanks to everyone that helped <3

Sweet, you can mess with ExposureCompensation right off the bat and even the game itself has no flash load.. Black to Black fade to intro screen(s) to fade to game. Looks great and could be as much smoke as you need.

Most of my scripts that can get away with it all look like
Task.Wait(2), Task.Wait(2.5), Task.Wait(3), Task.Wait(3.5) up top.
Letting the game breathe while loading = 2–3 second perfect loads.
You have to watch which needs to be loaded before which, however.
Some scripts can’t use this like this..

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character) task.wait(1) --or whatever
        -- but you still can do this
    end)
end)
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") task.wait(1)

  --ya you're going to have to wait a bit buddy we got more going on than
  --you and you're clogging up the pipeline pal