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

How do I get the players playergui when then touch a brick?

Hey! Quick question! How would I get the player from the character when they touch a brick so I can access a gui inside a players player gui?

3 answers

You need to find hit.Parent's name and use findFirstChild in Players to find the player. You can then access PlayerGui.

debounce=false
local sp=script.Parent
function T(hit)
debounce=true
local char=hit.Parent
local players=game:GetService("Players")
local player=players:findFirstChild(char.Name)

local gui=player.PlayerGui.(GUINAMEHERE)
wait(1)
debounce=false
--do whatever here
end

You're welcome.

You can use Parameters to access the Player while using a touch event. I post a example on How to use Parameters below:

script.Parent.Touched:connect(function(Player)
	print(Player.Parent.Name)--This prints out the name of the Player who "activated" the script.
game.Players[Player.Parent.Name].PlayerGui-- Add the Gui Path here.
end)

Here more information about Parameters

You can also use GetPlayerFromCharacter() to get the Player from the Character. Here's a example on how to use it.

	script.Parent.Touched:connect(function(Player)
local Character = game.Workspace.Player
	local plr = game.Players:GetPlayerFromCharacter(Character)
print(plr.Name)
	plr.PlayerGui-- Put the Path of the Gui here
end)

If you want information about GetPlayerFromCharacter()

4 comments

0

game.Players[Player.Parent.Name].PlayerGui.ScreenGui.Frame.Script.Disabled = false won't do anything. :(

0

You can access the Player by GetPlayerFromCharacter()

0

Also are you trying to enable or disable the script?

0

Thanks boss. This worked for me. game.Players[Player.Parent.Name].PlayerGui

I use this script myself works everytime.

local gui = script["put gui inside of script"]
script.Parent.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr and not plr.PlayerGui:findFirstChild(gui.Name) then
    local cl = gui:Clone()
    cl.Parent = plr.PlayerGui
	coroutine.resume(coroutine.create(function()

local human = hit.Parent:FindFirstChild("Humanoid") 
    --Basically this just checks to see if it is a real player touching this brick.
if (human ~= nil) then --If it is a real player, then DESTROY THEM!
	human.Health = 0 --Your Health Is Now 0.
end
		wait(5)
		for i = 0, 1,.1 do 
			wait()
			
		end
		cl:Destroy()
	end))
    end
end)

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