Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To Access the PlayerGui?

--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

       function onPJ(plr)
	  local humanoid = plr.Parent:FindFirstChild("Humanoid")
	 if humanoid then
		local player = game.Players:GetPlayerFromCharacter(plr.Parent)
		local alreadygui = player.PlayerGui:FindFirstChild("Buy")
		if alreadygui == nil then
		print("nothere")
		local GUI = script.Buy:clone()
		GUI.Parent = player.PlayerGui
		elseif alreadygui ~= nil then
		print("ishere")
		
		
    player.PlayerGui.Buy.Frame.Visible=true
		
		         end
		
		   end
	    end
 end

  script.Parent.Touched:connect(onPJ)

6 comments

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.

0

^^^^

0

You can only get player gui from a local script

1

please.. format your code

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

1

Edit: Placed code in a code block

3 answers

Through a** LocalScript**

local player = game.Players.LocalPlayer

local playergui = player:WaitForChild("PlayerGui")

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.

2 comments

0

a local script can call a touched event

0

in fact you can get the player with the touched event on the server by using :GetPlayerFromCharacter()

Change this

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

To this

local player = game.Players.LocalPlayer

and to access the PlayerGui just do this

local playergui = player.PlayerGui

Do this with a localscript

This discussion is preserved as it was. New answers, comments, and votes are closed.