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

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

Asked by
Nidoxs 190
10 years ago

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

Log in to vote
6
Answered by 10 years ago

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

01debounce=false
02local sp=script.Parent
03function T(hit)
04debounce=true
05local char=hit.Parent
06local players=game:GetService("Players")
07local player=players:findFirstChild(char.Name)
08 
09local gui=player.PlayerGui.(GUINAMEHERE)
10wait(1)
11debounce=false
12--do whatever here
13end

You're welcome.

Ad
Log in to vote
5
Answered by 10 years ago

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

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

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.

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

If you want information about GetPlayerFromCharacter()

0
game.Players[Player.Parent.Name].PlayerGui.ScreenGui.Frame.Script.Disabled = false won't do anything. :( Nidoxs 190 — 10y
0
You can access the Player by GetPlayerFromCharacter() UserOnly20Characters 890 — 10y
0
Also are you trying to enable or disable the script? UserOnly20Characters 890 — 10y
0
Thanks boss. This worked for me. game.Players[Player.Parent.Name].PlayerGui MikeStrider 0 — 5y
Log in to vote
3
Answered by
Hero_ic 502 Moderation Voter
10 years ago

I use this script myself works everytime.

01local gui = script["put gui inside of script"]
02script.Parent.Touched:connect(function(hit)
03    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
04    if plr and not plr.PlayerGui:findFirstChild(gui.Name) then
05    local cl = gui:Clone()
06    cl.Parent = plr.PlayerGui
07    coroutine.resume(coroutine.create(function()
08 
09local human = hit.Parent:FindFirstChild("Humanoid")
10    --Basically this just checks to see if it is a real player touching this brick.
11if (human ~= nil) then --If it is a real player, then DESTROY THEM!
12    human.Health = 0 --Your Health Is Now 0.
13end
14        wait(5)
15        for i = 0, 1,.1 do
View all 22 lines...

Answer this question