Attempt to index nil with "Name" in a regular script

Okay, so recently I have been trying to make a blacklist DSS on roblox, that works when a player says the following command and is a specific rank in a certain group. The only issue I am getting on this is at Line 21 I am getting an error saying: "Attempt to index nil with “Name”. Thank you in advance for any help that is given :smile:

Code:

local blacklistedusers = {1,1,1,1} -- User id not name
local players = game:GetService("Players")
local player = players.LocalPlayer
local dss = game:GetService("DataStoreService")
local blacklistds = dss:GetDataStore("BlacklistedUsers")
-------------------
local groupid = 4170345
local adminrank = 100

for i,v in pairs(game.Players:GetPlayers()) do
	for i,banneduserid in pairs(blacklistedusers) do
	if v.UserId == banneduserid then
		local background = v.PlayerGui.ModCall.Background
		background.Call.Visible = false
		background.Reason.PlaceholderText = "You are blacklisted from using this, appeal in the discord."
		background.Reason.PlaceholderColor3 = Color3.new(0,0,0)
		background.Subtitle.Text = "Your are blacklisted"
		end
	end
end
print(player.Name) -- Part with the error --
player.Chatted:Connect(function(msg)
	print(msg)
	if msg:sub(1,11) == "/blacklist " and player:GetRankInGroup(groupid) >= 100 then
		blacklistds:SetAsync(player.UserId, true)
		player:Kick("Your blacklisted from using the Mod Call - NAC :)")
	end
	
	if msg:sub(1,13) == "/unblacklist " and player:GetRankInGroup(groupid) >= 100 then
		blacklistds:SetAsync(player.UserId, false)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if blacklistds:GetAsync(plr.UserId, true) then
		local background = plr.PlayerGui.ModCall.Background
		background.Call.Visible = false
		background.Reason.PlaceholderText = "You are blacklisted from using this, appeal in the discord."
		background.Reason.PlaceholderColor3 = Color3.new(0,0,0)
		background.Subtitle.Text = "Your are blacklisted"
	end
end)

LocalPlayer is limited to the client, assuming you’re doing this in a server script (because of datastoreservice being limited to the server for obvious reasons.)

try using v.Chatted:Connect(function(msg)
or on line of error, do print(v.Name)

Of course, move those inside of the loop.

2 Likes

It seems that you may be mixing up localscripts and regular scripts, the localplayer can only be referred to from a localscript. Preceding the print(player.Name) is a line of code which seems to try to access playerguis which would not work from a localscript (but it’d also not be very efficient on the server either because you’re trying to access the client, try using remote events).

1 Like

I understand but aren’t you able to get the player with:

local players = game:GetService("Players")
local player = players.LocalPlayer

in a script?

You would only be able to do this from within a local script, not a server script.

Not over the server, no. (30 characters sahkjasgdjk;lndsmbg)

Ahh alright, I shall try this.

@ViserLizz Okay, thank you this has worked, I’ve also ran into this issue a few times with a few other scripts I have been working on.

1 Like