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

How can I get player from character?

Asked by 9 years ago

When the character touches a brick a GUI becomes visible.

I tried the GetPlayerFromCharacter method but the output is **22:05:01.018 - GetPlayerFromCharacter is not a valid member of Model 22:05:01.019 - Script 'Workspace.Part.Script', Line 4 22:05:01.021 - Stack End****

Here is the code

function onTouch(brick)
local p = brick.Parent:findFirstChild("Humanoid")
if p ~= nil then
p.Parent:GetPlayerFromCharacter()
end
end
script.Parent.Touched:connect(onTouch)

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

The GetPlayerFromCharacter funtion is a function of game.Players and uses the character you're wanting to get the player from as it's arguments!

function onTouch(brick)
    local p = brick.Parent:FindFirstChild("Humanoid")
    if p ~= nil then
        local plr = game.Players:GetPlayerFromCharacter(brick.Parent)
    end
end

script.Parent.Touched:connect(onTouch)

EDIT

If you need to get the PlayerGui of the player, the PlayerGui is a child of the Player.. so just index it like `plr.PlayerGui``

0
It won't allow me to access things like PlayerGui. How would I do this? GianniKun 40 — 9y
0
If you got player using the above script, then playergui would be a child of the player for example print(player.PlayerGui.Name) would just print the name of playerGui, which is "PlayaerGui" buoyantair 123 — 9y
0
Edited Goulstem 8144 — 9y
Ad

Answer this question