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()
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
local function checktest (player)
print("Check 1")
local PlayerValue = player.PlayerGui.Value
if PlayerValue.Value == 2 then
print("Check 2")
end
end
checktest()
@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.