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

Detecting a player's membership type and then enabling a certain gui?

What I'm trying to do is get a player's membership type, (BC), and then display a certain image based on that.

I keep getting the error,

16:36:52.835 - Test is not a valid member of PlayerGui
16:36:52.836 - Script 'ServerScriptService.Script', Line 15
16:36:52.836 - Stack End

Inside ServerScriptStorage, normal script

game.Players.PlayerAdded:connect(function(p)
	if p.MembershipType == Enum.MembershipType.BuildersClub then
		p.PlayerGui.Test.BC.Visible = true
		p.PlayerGui.Test.NBC.Visible = false
		print(p.MembershipType)
	elseif p.MembershipType == Enum.MembershipType.TurboBuildersClub then
		p.PlayerGui.Test.TBC.Visible = true
		p.PlayerGui.Test.NBC.Visible = false
		print(p.MembershipType)
	elseif p.MembershipType == Enum.MembershipType.OutrageousBuildersClub then
		p.PlayerGui.Test.OBC.Visible = true
		p.PlayerGui.Test.NBC.Visible = false
		print(p.MembershipType)
	elseif p.MembershipType == Enum.MembershipType.None then
		p.PlayerGui.Test.NBC.Visible = true
		print(p.MembershipType)
	end
end)

3 answers

✓ Accepted answer

If you have FilteringEnabled turned on which can be found within Workspace, the server can't find stuff within a player's PlayerGui.

http://wiki.roblox.com/index.php?title=API:Class/Workspace/FilteringEnabled

When this property is true, a Player's PlayerGui will not replicate to the server. It will only exist on the client. This means that Scripts within PlayerGui will not run, and the server will be unable to access it.

I recommend putting this script within StarterCharacterScripts which can be found inside StarterPlayer (make sure you use a localscript)

local p = game.Players.LocalPlayer -- gets the local player running this script
p:WaitForChild("PlayerGui"):WaitForChild("Test"):WaitForChild("BC")
p.PlayerGui.Test:WaitForChild("NBC")
-- using WaitForChild is a good idea locally to wait until our GUIs are finished before using scripts to manipulate them.
    if p.MembershipType == Enum.MembershipType.BuildersClub then
        p.PlayerGui.Test.BC.Visible = true
        p.PlayerGui.Test.NBC.Visible = false
        print(p.MembershipType)
    elseif p.MembershipType == Enum.MembershipType.TurboBuildersClub then
        p.PlayerGui.Test.TBC.Visible = true
        p.PlayerGui.Test.NBC.Visible = false
        print(p.MembershipType)
    elseif p.MembershipType == Enum.MembershipType.OutrageousBuildersClub then
        p.PlayerGui.Test.OBC.Visible = true
        p.PlayerGui.Test.NBC.Visible = false
        print(p.MembershipType)
    elseif p.MembershipType == Enum.MembershipType.None then
        p.PlayerGui.Test.NBC.Visible = true
        print(p.MembershipType)
    end

Hope this helps. If you have any questions then feel free to post a comment below.

It's recommend you use :WaitForChild(), as it'll pause the script until the specified child is found. When working with PlayerGui, you'll need to use it a lot.

This means that "Test" Is not in the Playergui. If you are certain it is there, use :WaitForChild() and see if that makes any difference! If not, you'll need to put a ScreenGui inside StarterGui called "Test!"

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