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

ScreenGui is not a valid member of PlayerGui?

Asked by 5 years ago
Edited 5 years ago

hello! I am trying to code a game with a shop that opens when you stand on a brick. Whenever I try this it tells me that 'ScreenGui is not a valid member of PlayerGui', which I can confirm it is. Here is my script Below. Thank you anyone who helps me :D

script.Parent.Touched:connect(function(hit)
local humanoid=hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~=nil then
    local user = hit.Parent.Name
    local ScreenGui = game.Players[user].PlayerGui:FindFirstChild("ScreenGui")
    local frame = ScreenGui:FindFirstChild("UpgradesFrame")
    game.Players[user].PlayerGui[ScreenGui][frame].Visible = true
    end
end)    

P.S I have tried just doing game.Players[user].PlayerGui.ScreenGui.. but still doesn't work. WaitForChild doesn't work either '-'

0
Is this a server script? DinozCreates 1070 — 5y
0
^ if so use an event The_Pr0fessor 595 — 5y
1
If its not you're referencing the player incorrectly, if so you need to use an event, like professor said. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The contents of StarterGui are cloned locally into the player's PlayerGui, so the server will not see the contents of PlayerGui unless the server itself placed it.

It is possible to listen for this event client side, so do that instead.

-- # local script under the frame
local frame = script.Parent
local client = game:GetService("Players").LocalPlayer
local part -- # path to your part

part.Touched:Connect(function(other)
    frame.Visible = other:IsDescendantOf(client.Character)
end)

obj:IsDescendantOf(ancestor) returns true if the obj is the descendant of ancestor, false otherwise. So this script will literally just set the frames visibility to the return value of the IsDescendantOf function.

The reason this should be done is because anything can touch parts, not only players, and so when the part is touched you should check if the local player is the the one who touched it or else the frame goes visible for everyone else

0
Thank you :) Worked like a charm! PoppyandNeivaarecute 134 — 5y
Ad

Answer this question