Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 9 days ago
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)

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

2 answers

Log in to vote
0
Answered by
AspectW 426 Moderation Voter
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

    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)
Ad
Log in to vote
0
Answered by 9 days ago

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)

Answer this question