Attempt to Index Nil with 'PlayerGui'

Hey! I am using a service known as TopbarPlus, and it keeps erroring even though I haven’t modified the script at all. So I am going to modify it now to fix it. The error piece of code follows:

local localPlayer = game:GetService("Players").LocalPlayer
local playerGui = localPlayer:FindFirstChild("PlayerGui")
topbarPlusGui.Parent = playerGui

This is only a snippet of the script; the script is 300+ lines long.

The error occurs on line 3 and I don’t know why it’s erroring, because I got this from an official website and this is a module script, so it should be able to call local players.

Thank you for your time.

try using it without findfirstchild, if it doesn’t work try using waitforchild

1 Like

you can’t get the local player from a module script… only if it was required from a local script…

1 Like

if module was required by client then it can, servers cant

1 Like

yeah just noticed that, thanks though

1 Like

so apparently i was using the program wrong; i was supposed to make a LocalScript (with the same code) and put it as a child of StarterPlayerScripts; thanks for trying to help though

then mark this reply as the solution

what would WaitForChild() Change? Aren’t local scripts execute when player object is created? Just do localPlayer.PlayerGui

well i use it sometimes, it gave me errors that playergui was nil sometimes so yh

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.