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

(ANSWERED) How come I can't access the PlayerGui?

Asked by
Slatryte 104
4 years ago
Edited 4 years ago

Introduction

Hello there, I am having a problem with the PlayerGui property of the player. I am trying to access the player's PlayerGui, but it will not work.

My script:

function myFunction(player)
    local part = workspace.Part
    local clone = part.GUI:Clone()
    clone.Parent = player.PlayerGui
end
myFunction()

Conclusion

Can somebody help me?

0
You aren't passing any variables when you call the function. It has no ideas what "player" is. Jexpler 63 — 4y
0
How can I describe "player...?" Slatryte 104 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

If you are using a local script to do this, you can find the player by using game.Players.LocalPlayer, and use the example below.

function myFunction(player)
    local part = workspace.Part
    local clone = part.GUI:Clone()
    clone.Parent = player.PlayerGui
end
myFunction(game.Players.LocalPlayer)

If this is a server script, you need to get another way to find that player. If that is the case, please write a response saying what you need to happen to have the function happen. From there, I can help you further.

0
Let me try it... Slatryte 104 — 4y
0
Thanks a bunch! Slatryte 104 — 4y
Ad

Answer this question