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

Why won't this script find a specific local script inside a player's PlayerGui?

Asked by 5 years ago
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?

0
you can't use "and" that many times DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
crywink 419 Moderation Voter
5 years ago

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.

0
Thanks for that last bit, that's what I was looking for. I'll just try something different to work around it! KingCheese13 21 — 5y
Ad

Answer this question