Still have questions? Join our Discord server and get real time help.
0

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

Edited by raid6n 9 days ago

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)


0
AspectW 426
9 days ago
Edited 9 days ago

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

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)

0

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

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)