ServerScriptService.PremiumPlayers:4: attempt to index nil with 'MembershipType' error

So I was making a Overhead Gui for Roblox Premium Players
and i watched alvinblox’s overhead gui tutorial and edit the code with the Premium Payouts and an error happened
Error: ServerScriptService.PremiumPlayers:4: attempt to index nil with ‘MembershipType’

local Players = game:GetService("Players")
local player = Players.LocalPlayer
 
if player.MembershipType == Enum.MembershipType.Premium then
	local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")
    game.Players.PlayerAdded:Connect(function(player)
		local clonedgui = billboardgui:Clone()
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
		clonedgui.TextLabel.Text = "Premium"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(231,206,12)
end)
end

Help me cause i will update my game

You’ve put this in a ServerScript, I think if you put it in a LocalScript in StarterPlayerScripts, it should work :+1:

local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
 player.CharacterAdded:Connect(function()
if player.MembershipType == Enum.MembershipType.Premium then
	local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")
    
		local clonedgui = billboardgui:Clone()
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
		clonedgui.TextLabel.Text = "Premium"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(231,206,12)

end
end)
end)

It’s because you cant get a LocalPlayer from a server script, it’s local.

2 Likes

This is a server script, LocalPlayer can only be referenced in LocalScripts, as it’s illogical for a server script to know what the LocalPlayer is

If you want a server side version of this, use a StarterCharacterScript to automatically apply the billboard gui OR use the code in the reply above

(if you use the code above, give him the solution, not me)

2 Likes