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

attempt to index nil with 'MembershipType' Can you help me?

So I'mm trying to do a premium checker to see if its legit or not, but i get this error Workspace.Model.Button.ClickDetector.Script:7: attempt to index nil with 'MembershipType' and heres the code:

script.Parent.MouseClick:Connect(function()
	local Players = game:GetService("Players")
	local player = Players.LocalPlayer
	local gui =  game.StarterGui.Premuin.Frame
	local lab =  game.StarterGui.Premuin.Frame.TextLabel
	
	if player.MembershipType == Enum.MembershipType.Premium then -- This line is having a problem
		gui.Visible = true
		lab.Text = "Status: You have Premium!"
		wait(5)
		gui.Visible = false
		
	elseif player.MembershipType == Enum.MembershipType.None then
			lab.Text = "Status: You do not have Premium"
			wait(5)
			gui.Visible = false
	end
end)

And Here's the devform: https://developer.roblox.com/en-us/articles/premium-payouts

2 answers

✓ Accepted answer

You can not get the LocalPlayer through a ServerScript, however the MouseClick event passes the player who clicked as a parameter.

script.Parent.MouseClick:Connect(function(player)
    local gui =  game.StarterGui.Premuin.Frame
    local lab =  game.StarterGui.Premuin.Frame.TextLabel

    if player.MembershipType == Enum.MembershipType.Premium then
        gui.Visible = true
        lab.Text = "Status: You have Premium!"
        wait(5)
        gui.Visible = false

    elseif player.MembershipType == Enum.MembershipType.None then
        lab.Text = "Status: You do not have Premium"
        wait(5)
        gui.Visible = false
    end
end)

The is an additional fix you would have to make. When you change it in startergui, it does just that, but it won't do anything to the player's gui. You have to edit the gui as a child of a player's PlayerGui which is a direct child of the player instance.

script.Parent.MouseClick:Connect(function(player)
    local gui =  player.PlayerGui.Premuin.Frame
    local lab =  player.PlayerGui.Premuin.Frame.TextLabel

    if player.MembershipType == Enum.MembershipType.Premium then
        gui.Visible = true
        lab.Text = "Status: You have Premium!"
        wait(5)
        gui.Visible = false

    elseif player.MembershipType == Enum.MembershipType.None then
        lab.Text = "Status: You do not have Premium"
        wait(5)
        gui.Visible = false
    end
end)

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