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

Output says attempt to "index field 'LocalPlayer' (a nil value)" when trying to open Gui?

Asked by 4 years ago

i'm making a Gui that pops up when you click on a brick.This is the script

script.Parent.MouseClick:Connect(function()
    game.Players.LocalPlayer.PlayerGui.talk.enabled = true

end)
0
is it a localscript? localplayer can only be called from a localscript u1v6 22 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

To make a script do something when a part is clicked, you need a ClickDetector. Also, you would make the gui invisible, then set it to visible (don't use ".Enabled" to make it appear).

Why you got the error you got: Scripts aren't the same as local scripts; you can only use "game.Players.LocalPlayer" on a local script.

0
alright thanks MartinFrog 6 — 4y
Ad
Log in to vote
0
Answered by
0msh 333 Moderation Voter
4 years ago
Edited 4 years ago

if that brick is in workspace,

game.Players.LocalPlayer

would not work so it should look something like this (not tested):

script.Parent.MouseClick:Connect(function(plr)
   plr:FindFirstChild("PlayerGui").talk.Enabled = true
end)

Answer this question