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
3 years ago
Edited 3 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?

local UpgradePart = script.Parent

UpgradePart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = hit.Parent.Parent
        player.PlayerGui.UpgradesShop.MainFrame.Visible = true
    else
        return nil
    end
end)
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 — 3y
0
true cancle5 120 — 3y
0
true cancle5 120 — 3y
0
true cancle5 120 — 3y
View all comments (2 more)
0
true cancle5 120 — 3y
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 — 3y

3 answers

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

Try this:

local UpgradePart = script.Parent

UpgradePart.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player then
        Player.PlayerGui.UpgradesShop.MainFrame.Visible = true
    end
end)
0
After the first time you can't open it anymore. CodeWon 181 — 3y
0
Wdym? esepek 103 — 3y
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 — 3y
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 — 3y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

PlayerGui is not inside of the character!

try getting the player

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

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

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

Answer this question