Changing visible of the gui if the player has a certain value

What do you mean the error will still lie?

Edit: I am going to try it out myself.

I can’t tell if I myself wrote it incorrectly or for some reason MainGui isn’t being replicated to their PlayerGui? If it’s jsut a simple warning, shouldn’t it still work afterwards once it finds MainGui?

Every UI replicates to PlayerGui automatically. If you want to make a ui for only one player you can create a screenGui with and make the parent player gui.

Edit: I’m pretty sure this will only work in a LocalScript.

Say I place a ScreenGui inside StarterGui and insert this script:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local screenGui = PlayerGui:WaitForChild("MainGui")

I believe if for some reason your client is extremely delaying, it would result in that warning sometimes (But since my laptop has the durability of a toaster inside a microwave I can’t confirm)

No, I am pretty sure it won’t cause huge lag unless something in server-side happens such as Roblox having critical problems. But if the clients computer is super laggy there’s no solution for that.

Will the script work even if it shows a warning?

It will unless it gives an error. It just shows you a warning as it can yield infinitely if the thing you request in the variable doesn’t exist.

Edit: I will try to implement the same to my Rock, Paper, Scissors game to just to see if it’s working.

The player has entered the game. I have printed the value. And it says it is false. Then the Off gui should be on instead of the on gui. I am not getting errors with the script, but it does not do what it is asked to do.

Wait, what? Is the bool value stored in the player? And also I did not add any code that changes the bool value if you checked it. I just checked if the bool value changed and if it did call a function.

Edit: If you change the bool value it’ll be fine I guess. I did not add one as I don’t know where you wanted to check the bool value.

It might be because the script only executes once the .PlayerAdded event fires. The .PlayerAdded event doesn’t fire for the LocalPlayer, only for players which join after the LocalPlayer.

Try taking the script out of the .PlayerAdded event (this would also avoid the code unnecessarily executing again everytime another player joins)

Edit: Also you should use an if/else or an if/elseif statement instead of 2 separate if statements (generally when using two separate if statements you’re checking for multiple things which both need to be evaluated for the script to work. In this case, there’s only one value being checked)

Okay, I rewrited the code so it checks whenever the player joins too, so it doesn’t need changing the bool value to see it.

local boolvalue = --wherever your value is
local player = game.Players.LocalPlayer
local playergui = LocalPlayer.PlayerGui
local screenGui = PlayerGui:WaitForChild("MainGui")
local settingsFrame = screenGui.SettingsFrame
local on = settingsFrame.BackgroundOn
local off = settingsFrame.BackgroundOff

local function makeGUIVisible()
      if bool1.Value == true then
           off.Visible = false
		   on.Visible = true
          off.Visible = true
		  on.Visible = false


--Of course you can change up the function to make it different.

This should work I guess.

Edit: Did it work?

1 Like

I am really glad I could help you out! If you ever struggle in something don’t be afraid to make a post!

1 Like

Sometimes it works and sometimes it doesn’t I found out if the player join the game. I am not getting any errors, but it’s strange.

What do you mean? I don’t see anything wrong in the code. Is this a problem on Roblox’s side?

Yes if I test it in the roblox servers. Sometimes it works and sometimes it doesn’t when the player enters the game.

That’s weird. I don’t think there are any mistakes in the scripts.