(Note: I found posts about the same error, but they did not help with this specific script.)
Hello!
I was making a script to create a GUI effect, but I cannot make a variable for the GUI, referencing it as:
local loading = player.PlayerGui.Game.Loading
(Note that “player” is defined by the PlayerAdded function)
I keep getting an error in the console about this variable:
ServerScriptService.Folder.Loading:4: attempt to index nil with ‘PlayerGui’
I’m not sure what I’m doing wrong, but I think it has to do with how I define “player” in the PlayerAdded function. I appreciate any help!
game.StarterGui.Game.Loading.Visible = true
local function loadingTransition(player)
local loading = player.PlayerGui.Game.Loading
local loadingHeader1 = loading["1"]
local loadingHeader2 = loading["3"]
player.PlayerGui:WaitForChild("MainMenu")
wait(3)
local x = 0
local iteration = 0.1
while x < 1 do
loading.BackgroundTransparency = x + iteration
loadingHeader1.TextTransparency = x + iteration
loadingHeader2.TextTransparency = x + iteration
loadingHeader1.BackgroundTransparency = x + iteration
loadingHeader2.BackgroundTransparency = x + iteration
x = x + iteration
wait(0.25)
end
loading.Visible = false
end
game.Players.PlayerAdded:Connect(loadingTransition())