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

What does "PlayerGui is not a valid member of Part" mean?

Asked by
JJ_B 250 Moderation Voter
8 years ago

I made a script to show a GUI when touched.

function loadscreen(hit)
    if not hit.PlayerGui:FindFirstChild("Gui") then
        local gui = script.Gui:clone()
        gui.Parent = hit.PlayerGui
    end
end


script.Parent.Touched:connect(loadscreen)

However, the outputs shows the message seen in the title and it fails to work. Help?

1 answer

Log in to vote
3
Answered by
Rhyles 80
8 years ago

The error message isn't lying! :P

When whatever is being connected to the Touched event is touched, the variable 'hit' will (almost?) always be a Part. Parts don't usually contain PlayerGuis, Player objects do. Somehow you need to find the Player object from that 'hit' part. Good luck!

0
Have your first rep. :P ChemicalHex 979 — 8y
0
Why, thank you! :D Rhyles 80 — 8y
Ad

Answer this question