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

How To Access the PlayerGui?

Asked by 6 years ago
Edited by Shawnyg 6 years ago

--when the player touch this brick it will give him a gui , but if the player already have one this script wont give it to him and this is what I want . the only problem is in line 14 , I cant access the playergui and I don't know how to fix it

01      function onPJ(plr)
02     local humanoid = plr.Parent:FindFirstChild("Humanoid")
03    if humanoid then
04       local player = game.Players:GetPlayerFromCharacter(plr.Parent)
05       local alreadygui = player.PlayerGui:FindFirstChild("Buy")
06       if alreadygui == nil then
07       print("nothere")
08       local GUI = script.Buy:clone()
09       GUI.Parent = player.PlayerGui
10       elseif alreadygui ~= nil then
11       print("ishere")
12 
13 
14   player.PlayerGui.Buy.Frame.Visible=true
15 
View all 22 lines...
0
Format your code inside a Code block. To do that: Edit this post, Click on the blue Lua icon which will insert 2 squiggly (~) lines. Paste your code in between the two lines. xPolarium 1388 — 6y
0
^^^^ DevSersponge 5 — 6y
0
You can only get player gui from a local script LegosAreGood05 -2 — 6y
1
please.. format your code Sublivion 1 — 6y
View all comments (2 more)
0
The server does not have access to the children of any PlayerGui folder.. if you want to do UI code set up a front end Sublivion 1 — 6y
1
Edit: Placed code in a code block Shawnyg 4330 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

Through a** LocalScript**

1local player = game.Players.LocalPlayer
2 
3local playergui = player:WaitForChild("PlayerGui")
Ad
Log in to vote
0
Answered by 6 years ago

There is actually no way to get to the player with the touch event on the normal script. And you cant use a localScript to call a touched event. the best and probably only way is using RemoteEvents. Call the remote when the player is touched. call the remote by client

im so sorry if i explained it POORLY. if you can understand it tho, please try it.

0
a local script can call a touched event theking48989987 2147 — 6y
0
in fact you can get the player with the touched event on the server by using :GetPlayerFromCharacter() User#23365 30 — 6y
Log in to vote
0
Answered by 6 years ago

Change this

1local player = game.Players:GetPlayerFromCharacter(plr.Parent)

To this

1local player = game.Players.LocalPlayer

and to access the PlayerGui just do this

1local playergui = player.PlayerGui

Do this with a localscript

Answer this question