#MainGui is not a valid member of PlayerGui "Players.<Player>.PlayerGui"

1 messages · Page 1 of 1 (latest)

paper latch
#

Hey, im getting this error even though I have MainGui in startergui

timid drift
#

could be getting called too early. try waitforchild

paper latch
rose dove
paper latch
#

in Starter PlayerScripts

rose dove
# paper latch Local

i think but like that the error happens because the StaterGui gets copied into PlayerGui only on the client side so like if the script is running on the server it won’t see the MainGui in PlayerGui idk if im correct

#

im most likely wrong lol

timid drift
paper latch
#
local player = game.Players.LocalPlayer
player.CameraMaxZoomDistance = 50

leaveGuiEvent.OnClientEvent:Connect(function()
    player.PlayerGui.MainGui.leaveButton.Visible = true
end)

player.PlayerGui.MainGui.leaveButton.MouseButton1Down:connect(function()
    leaveGuiEvent:FireServer()
    player.PlayerGui.MainGui.leaveButton.Visible = false
end)``` line 9
#

player.PlayerGui.MainGui.leaveButton.MouseButton1Down:connect(function()

paper latch
timid drift
#

oh i see the issue

#
local leaveGuiEvent = game.ReplicatedStorage.LeaveGuiEvent
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
player.CameraMaxZoomDistance = 50

leaveGuiEvent.OnClientEvent:Connect(function()
    player.PlayerGui.MainGui.leaveButton.Visible = true
end)

playerGui:WaitForChild("MainGui").leaveButton.MouseButton1Down:connect(function()
    leaveGuiEvent:FireServer()
    player.PlayerGui.MainGui.leaveButton.Visible = false
end)

paper latch
#
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
player.CameraMaxZoomDistance = 50

leaveGuiEvent.OnClientEvent:Connect(function()
    player.PlayerGui.MainGui.leaveButton.Visible = true
end)

playerGui:WaitForChild("MainGui").leaveButton.MouseButton1Down:connect(function()
    leaveGuiEvent:FireServer()
    player.PlayerGui.MainGui.leaveButton.Visible = false
end)``` Hey this is my current script and Im getting this error `Script 'Players.<Player>.PlayerScripts.LeaveButtonScript', Line 9`
#

@timid drift

timid drift
#

hi

#

ummm lets see

paper latch
#

Im confused because there is nothing on line 9

timid drift
#

so basically the script is called at runtime, and it's sometimes a race condition as to whether startergui has been duplicated by the time the script runs

#

send the full error

paper latch
#

Nvn it's working now