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

How to access the PlayerGui via script and this happens?

Asked by
Audiimo 105
7 years ago
Edited 7 years ago

1st Box: When I have this script run I get this message " ServerScriptService.Script:2: attempt to index field 'PlayerGui' (a nil value)". Also how to access the PlayerGui with scripts? I am unsure of what this means and how to do this. I have tried rerouting it to StarterGUI and it works (I'm asking about this so I can learn).

1st Box

game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    game.Players.player.Name.PlayerGui.EnterGui.TextLabel.Text = " " ..player.Name.. " has joined the game"    
    wait(5)
    script.Parent.PlayerGui.EnterGUI.TextLabel.Text = " "
end)
--This is my code for Players

2nd Box: It does work for StarterGui but that brings me to my next problem. I want it to remove the message after a wait, as shown in the Second box of code below, and that doesn't work as well. No error code appears and I am unsure as to what is wrong. Can you help with this. Thanks!

2nd Box

game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    game.StarterGui.EnterGui.TextLabel.Text = " " ..player.Name.. "has joined the game"
    wait(5)
    game.StarterGui.EnterGUI.TextLabel.Text = " "
end)
--This is my code for StarterGui
0
Both answers demonstrate your problems, but if you have FE on the server cannot access the PlayerGui lukeb50 631 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

In your first code you did a mistake. player is not a valid member of game.Players, which makes it nil. You don't use the name to access the children of the player To fix this, try typing this down in your first script

game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    player.PlayerGui.EnterGui.TextLabel.Text = " " ..player.Name.. " has joined the game"    
    wait(5)
    player.PlayerGui.EnterGUI:Destroy()
end)
--This is my code for Players

Hopefully this works, if not, please ask as many questions as you want

0
rip you answered before me Astilev 30 — 7y
0
It Works! Thank You! Audiimo 105 — 7y
0
Your welcome saSlol2436 716 — 7y
Ad
Log in to vote
1
Answered by
Astilev 30
7 years ago

When using PlayerAdded, the player parameter takes the instance of the player already, so if you do game.Players.player, the script looks for someone named "player" in Players. What you want to do is actaully player.PlayerGui or game.Players:WaitForChild(player.Name), both of which work fine.

Secondly, you don't want to mess around with StarterGui too much, since that just changes the template that is applied to everyone when they either reset or first join the game. If you want to change the message, be sure to access PlayerGui instead of StarterGui, which applies to that specific player real-time.

Answer this question