Attempt to call a nil with value

  1. What do you want to achieve? Keep it simple and clear!
    Get Rid of errors.
  2. What is the issue? Include screenshots / videos if possible!
    Attempt to call a nil with value = 275 line
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    nothing.

First Code:

function AddPlayer(Player)
	if not game.ReplicatedStorage.Moderation.Players:FindFirstChild(Player.Name) then
		local IntValue = Instance.new("IntValue")
		IntValue.Name = Player.Name
		IntValue.Value = Player.UserId
		IntValue.Parent = game.ReplicatedStorage.Moderation.Players
		end
	end

Second Code:

game.Players.PlayerAdded:connect(function(Player) AddPlayer(Player) end)
for _, Player in pairs(game.Players:GetPlayers()) do
	AddPlayer(Player) -- problem here
end
1 Like

You should probably print what Player prints back before trying to call the function

game.Players.PlayerAdded:Connect(AddPlayer)

for _, Player in pairs(game.Players:GetPlayers()) do
    print(Player)

	AddPlayer(Player) -- problem here
end

Also try changing your function to a local function?

2 Likes

Sorry, but I couldn’t change my function to a local function because it’s an error with print (ERROR TO FIND LEADERSTATS WHEN GETTING DATA)

also, I have AddCharacter()

local AddedCharacter = require(script.AddedCharacter)
--   ^^^ to first code ^^^
	AddedCharacter(Player)
			
	Player:WaitForChild("Events")		
	Player:WaitForChild("Values")		
	Player:WaitForChild("VIP")		
	Player:WaitForChild("Chunks")
				
	local LeaderStats = Player.Values.References.LeaderStats		
	local ServerSideStats = game.ReplicatedStorage.ResourceLibrary.ExamplePlayer:Clone()	
	ServerSideStats.Name = Player.Name		
	ServerSideStats.Parent = game.ServerScriptService.PlayerLeaderStats
	LeaderStats.Value = ServerSideStats
1 Like

there line orange when I put local function