function onTouched(hit) if hit.Parent:FindFirstChild("Head") == nil and hit.Parent:FindFirstChild("Torso") == nil and hit.Parent:FindFirstChild("Left Arm") == nil and hit.Parent:FindFirstChild("Left Leg") == nil and hit.Parent:FindFirstChild("Right Arm") == nil and hit.Parent:FindFirstChild("Right Leg") == nil then return end if hit.Parent.Humanoid == nil then return end if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.PlayerGui.Cam.Disabled = false end --blah blah blah ... the rest of my script script.Parent.Touched:connect(onTouched)
The script finds the PlayerGui fine and I have confirmed this, however "Cam" is a local script meant to change a player's camera position and it always says that it is not a valid member of PlayerGui. Why?
Hey there!
To start off, there are a lot of redundant if/then clauses in your code. I assume on line 2 you're trying to make sure that the "thing" touching your part is a character, you don't really need those. All you really need is the Humanoid check on line 4 and maybe a HumanoidRootPart check to make sure the touched event isn't being spammed when all of the body parts touch it.
Also, is your script a server script or a local/client script? If it is a server script, they cannot access the descendants of a player's PlayerGui.
Just leave a comment if this isn't exactly what you want or you're having any trouble.
If this was helpful remember to accept and upvote the answer.