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
8 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 8 years ago

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.

Ad
Log in to vote
5
Answered by 8 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:

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

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

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)

Answer this question