Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ScreenGui is not a valid member of PlayerGui?

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 '-'

3 comments

0

Is this a server script?

0

^ if so use an event

1

If its not you're referencing the player incorrectly, if so you need to use an event, like professor said.

1 answer

✓ Accepted answer

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

1 comment

0

Thank you :) Worked like a charm!

This discussion is preserved as it was. New answers, comments, and votes are closed.