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

PlayerGui is not a valid member of "Workspace" ?

Asked by
CodeWon 181
4 years ago
Edited 4 years ago

My touched event is supposed to open a gui. At first it opened for everyone when its supposed to open only for the player who touched it. So I edited it and now its broken. Whats wrong?

01local UpgradePart = script.Parent
02 
03UpgradePart.Touched:Connect(function(hit)
04    if hit.Parent:FindFirstChild("Humanoid") then
05        local player = hit.Parent.Parent
06        player.PlayerGui.UpgradesShop.MainFrame.Visible = true
07    else
08        return nil
09    end
10end)
1
I already gave you an answer, but basically you should get the player with GetPlayerFromCharacter. Because what you did is get the players Character s Parent , wich is workspace but the PlayerGui isnt in workspace but in the Player intself. esepek 103 — 4y
0
true cancle5 120 — 4y
0
true cancle5 120 — 4y
0
true cancle5 120 — 4y
View all comments (2 more)
0
true cancle5 120 — 4y
0
If you teying to make a gui show up when touching a part, I advice you on watching AlvinBlox video talking about it https://youtu.be/6r_PBSXzOmI OhBrotherGaminYT 11 — 4y

3 answers

Log in to vote
2
Answered by
esepek 103
4 years ago

Try this:

1local UpgradePart = script.Parent
2 
3UpgradePart.Touched:Connect(function(hit)
4    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
5    if Player then
6        Player.PlayerGui.UpgradesShop.MainFrame.Visible = true
7    end
8end)
0
After the first time you can't open it anymore. CodeWon 181 — 4y
0
Wdym? esepek 103 — 4y
0
The first time you step on it, the gui opens. But the second time it doesn't, I hope I explained that well enough CodeWon 181 — 4y
0
Well I would need to see the full project/ code because the script makes it Visible whenever you touch it. So you probably Disable the entire ScreenGui or something in another script /closescript. esepek 103 — 4y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
4 years ago

PlayerGui is not inside of the character!

try getting the player

1local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
Log in to vote
0
Answered by 4 years ago

You're referencing the player's character, not player, do

1local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

Answer this question