If statement issue

Just a quick explanation about PlayerGui. All GUI’s go in StarterGui, but when a player joins, a new folder is made that is parented to the player named PlayerGui. Everything in StarterGui is then cloned into the player’s PlayerGui.

Local Script in StarterGuii

local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local numberValue = PlayerGui:WaitForChild("Value")
local function checktest()
        if numberValue.Value == 2 then
              print("yes it is 2")
        else 
              print('the value is'..numberValue.Value)
       end
end         

checktest()

And where would I put the NumberValue or is it already added, because I don’t see it being added or like a new Instance.

The NumberValue would already be added, because everything from StarterGui is cloned into PlayerGui.

Pretend that the PlayerGui is the same as StarterGui. When you want to reference any GUIs, its the same path except instead of StarterGui its PlayerGui. The reason for PlayerGui is this, if there was only the StarterGui, multiple players would be sharing and changing the same GUIs. Because everything is cloned into each playergui, every player has their own Guis.

--it looks like you want to say this, but you can't because changing StarterGui doesn't do anything
local textlabel = game.StarterGui.ScreenGui.Textlabel

--correct 
local textlabel = player.PlayerGui.ScreenGui.Textlabel

It says value is not a valid member of PlayerGui

Where the hell did you learn from that…

So when you look in StarterGui, there is a “Value” named “Value” parented to the StarterGui?

There is no value is StarterGui

Then why in your original code did you say the following??

if game.StarterGui.Value.Value == 2 then

I thought you said I didn’t have to add a numbervalue, ok i added it back and yes Value is parented to startergui

Go test by yourself, and be more respectful, clearly you don’t know too much about print :man_shrugging:

I’m sorry then, but I learn from AlvinBlox and almost all developers I’ve seen has put the brackets for functions. :roll_eyes:

I didn’t tell you to add a number value because I thought there was already one.

Oh but it still errors and says Value is not a member of PlayerGui

You named the number value “Value”, and it is a direct child of StarterGui?

This could be scoping error? Because I don’t see the indentation for the if statement.

The numbervalue is named value and yes it is a direct child of StarterGui

I know the problem, it needs time to load in. Give me a second.

Edit: I just fixed the code, try it now.

local function checktest (player)
	print("Check 1")
	local PlayerValue = player.PlayerGui.Value
	if PlayerValue.Value == 2 then
		print("Check 2")
	end
end

checktest()

try to use parameter for player and make varibles

@R0bl0x10501050
You don’t need parentheses for functions if you’re giving them a string literal or a table constructor.

Example:

function hi(val)
   print(val) -- needed here, as it's a variable
end

hi '100' -- not needed here, as it's a string literal
hi { 1, 2, 3 } -- not needed here, as it's a table constructor
hi( hi ) -- needed here, as it's a variable / function

Roblox’s Lua implementation builds upon the basic Lua language, so check out the reference manual for more syntax information: Lua 5.4 Reference Manual

From Section 3.4.10:

All argument expressions are evaluated before the call. A call of the form f{fields} is syntactic sugar for f({fields}) ; that is, the argument list is a single new table. A call of the form f'string' (or f"string" or f[[string]] ) is syntactic sugar for f('string') ; that is, the argument list is a single literal string.

2 Likes

This seems very complicated, I was never taught about this when I was starting to learn scripting. Where did you learn from?