Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"Attempt to index nil with PlayerGui"?

Asked by 4 years ago
game.Workspace.sFX.TimeHasBegunToMoveAgain:Play()
game.Players.LocalPlayer.PlayerGui.THBTMA.Enabled = true
wait (3)
game.Players.LocalPlayer.PlayerGui.THBTMA.Enabled = false

I need help.

0
On what lol? JuxedIX -45 — 4y

2 answers

Log in to vote
2
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The Attempt to index with exception refers to the trailing Instance, not the Instance of query. Therefore, there is an issue with the Player; the only scenario where LocalPlayer would be invalid is a ServerScript.

It is a common mistake many beginners make, as they're unaware of basic networking logic. A Server, is a mainframe that manages multitudes of Clients, and is not a Client itself. The LocalPlayer refers to the Player Object affiliated with the local machine; as aforementioned, a Server isn't a connected user, which is why we cannot allocate a Player Object from it.


The primitive difference between a LocalScript and a Script, is that each variation of the program is designed to run on it's respective end... LocalScripts will be ran via the ROBLOX Player on the user's device, whilst a Script will be ran on the ROBLOX Server.

This is why we can denote a Player Object through a LocalScript, as the program resides within the local machine


Though, we can still achieve your goal, just through a different approach. A Sever can still understand what Clients are connected, and what are connecting. We can catch a connecting user through the .PlayerAdded signal of the Players Service. From here, we can modify their User Interface:

local Players = game:GetService("Players")

local function EnablePlayerGui(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")
    local THBTMA = PlayerGui:WaitForChild("THBTMA")
    THBTMA.Enabled = true
end

Players.PlayerAdded:Connect(EnablePlayerGui)
0
Then what can i do to make the UI pop up? What can i change local player to, to make it work? EmptyVib_es 3 — 4y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago

You need to use :WaitForChild() in order to make the script wait for the PlayerGui object to be created on the player

game.Workspace.sFX.TimeHasBegunToMoveAgain:Play()
game.Players.LocalPlayer:WaitForChild('PlayerGui').THBTMA.Enabled = true
wait (3)
game.Players.LocalPlayer:WaitForChild('PlayerGui').THBTMA.Enabled = false
0
I get a new error now, "Attempt to index nil with 'WaitForChild'" EmptyVib_es 3 — 4y
0
Are you using a local script? if no, it should be a local script Leamir 3138 — 4y
0
Its a server wide script. Its supposed to show up for everyone. EmptyVib_es 3 — 4y
0
You can't use LocalPlayer on a server script, it only works at local scripts. Leamir 3138 — 4y
0
Help with? iivSnooxy 248 — 4y

Answer this question