The title says it all it keeps erroring about line 105 when data[plr.name]["endings"] is nil for a new player

code : (VERY LONG)

-- Ignore the very inefficient code
local dss = game:GetService("DataStoreService")
local ed = dss:GetDataStore("testds1")
local data = {}
local ndt = {
	["endings"] = {},
	["rdata"] = {
		["ADT"] = "bfft"
	}
}
local gendings = {}
-- IGNORE UNTIL LINE 105
local trusted = {
	Trusteds
}
local ms = game:GetService("MarketplaceService")


game.Players.PlayerAdded:Connect(function(plr)
	local _obje
	local pdat = ed:GetAsync(plr.UserId)
	-- Integrity Check
	if not pdat then
		data[plr.Name] = ndt
	else
		data[plr.Name] = pdat
		if data[plr.Name]["endings"] == nil  then
			data[plr.Name]["endings"] = {}
		end
		if data[plr.Name]["ADT"] == nil then
			data[plr.Name]["ADT"] = {}
		end
		data[plr.Name] = ed:GetAsync(plr.UserId)
	end
	game.ReplicatedStorage.CMode:FireClient(plr, "c")
	-- Donation Note
	if ms:UserOwnsGamePassAsync(plr.UserId, 17855260) then
		-- Player donated
		game.Workspace.tipnote.PinNote.Interactive:Destroy()
		game.Workspace.tipnote.CD:Destroy()
		game.Workspace.tipnote.PinNote.SurfaceGui.TextLabel.Text = "ty for donating"
	end
	
	local plrdata = data[plr.Name]
	
	-- Checks for star program
	
	
	if not plr:IsInGroup(4199740) then                    
		-- plr is not inside club
		if game.Workspace:FindFirstChild("YTNOTE") ~= nil then
			game.Workspace.YTNOTE:Destroy()
		end
	end	
	local ep = game.ServerStorage.Endings
	
	-- Tp player
	if plrdata["ADT"] == "bfst" then
		plr.Character.HumanoidRootPart.Postition = game.Workspace.TPPs.VTL
	end
	
	-- Note Engine
	local plrdats = data[plr.Name]
	if plrdats["NF"] ~= nil then
		local nfs = plrdats["NF"]
		if nfs == 1 then
			if game.Workspace:FindFirstChild("Not1") ~= nil and game.Workspace:FindFirstChild("Not3") ~= nil then
				game.Workspace.Not1:Destroy()
				game.Workspace.Not3:Destroy()
			end
		elseif nfs == 2 then
			if game.Workspace:FindFirstChild("Not1") ~= nil and game.Workspace:FindFirstChild("Not2") ~= nil then
				game.Workspace.Not2:Destroy()
				game.Workspace.Not1:Destroy()
			end
			
		elseif nfs == 3 then
			if game.Workspace:FindFirstChild("Not1") ~= nil and game.Workspace:FindFirstChild("Not2") ~= nil and game.Workspace:FindFirstChild("Not3") ~= nil then
				game.Workspace.Not1:Destroy()
				game.Workspace.Not2:Destroy()
				game.Workspace.Not3:Destroy()
			end
		end
	elseif plrdats["NF"] == nil then
		if game.Workspace:FindFirstChild("Not1") ~= nil and game.Workspace:FindFirstChild("Not2") ~= nil and game.Workspace:FindFirstChild("Not3") ~= nil then
			game.Workspace.Not1:Destroy()
			game.Workspace.Not2:Destroy()
			game.Workspace.Not3:Destroy()
		end
	end
	-- Done
	
	local endings = data[plr.Name]["endings"]
	gendings[plr.Name] = endings
	print(endings) -- NIL
	print(gendings[plr.Name]) -- NIL
	print(data[plr.Name]) -- Table
	print(data[plr.Name]["endings"]) -- NIL
	
	-- Endings Shower
	-- It fails here
	-- "Index nil with plr.Name"
	for _,v in pairs(gendings[plr.Name]) do
		if ep:FindFirstChild(v) ~= nil then
			ep:FindFirstChild(v):Clone().Parent = game.Workspace.Endings
		end
	end
	if #gendings[plr.Name] >= #game.ServerStorage.Endings:GetChildren() - 1  then
		ep:FindFirstChild("All Endings").Parent = game.Workspace.Endings
	end
	
	-- Amogus
	if math.random(1, 1000) ~= 532 then
		game.Workspace.Vent:Destroy()
	end
	
	-- Pro Gui
	
	if table.find(trusted, plr.Name) ~= nil then
		game.ServerStorage.ProPanel.Parent = plr.PlayerGui
	end
	
	-- Stats blabla
	local moneydata = Instance.new("Folder", game.ServerStorage.Plrdat)
	moneydata.Name = plr.Name
	local moneyvalue = Instance.new("IntValue", moneydata)
	moneyvalue.Name = "Money"
	moneyvalue.Value = 0
	local moneyframe = plr.PlayerGui.MoneGui.Frame
	moneyframe.Amount.Text = moneyvalue.Value
	moneyvalue.Changed:Connect(function()
		moneyframe.Amount.Text = moneyvalue.Value
	end)
	local isoutside = Instance.new("BoolValue", plr)
	isoutside.Name = "IsOut"
	isoutside = false
end)

game:BindToClose(function()
	for _, v in pairs(game.Players:GetChildren()) do
		local plr = v
		data[plr.Name]["endings"] = gendings[plr.Name]
		print(data[plr.Name])
		if data[plr.Name] ~= ed:GetAsync(plr.UserId) then
			ed:SetAsync(plr.UserId, data[plr.Name])
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	data[plr.Name]["endings"] = gendings[plr.Name]
	print(data[plr.Name])
	if data[plr.Name] ~= ed:GetAsync(plr.UserId)  then
		ed:SetAsync(plr.UserId, data[plr.Name])
	end
end)

script.Parent.Events.addEND.Event:Connect(function(data, plr)
	for _,v in pairs(gendings[plr.Name]) do
		if v == data then		
			return
		end
	end
	table.insert(gendings[plr.Name], data)
end)

script.Parent.Events.getEND.OnInvoke = function(plr)
	return gendings[plr.Name]
end

script.Parent.Events.MD.Event:Connect(function(plr, i, v)
	print(plr.Name)
	print(data[plr.Name])
	if data[plr.Name]["rdata"][i] == v then
		return
	end 
	data[plr.Name]["rdata"][i] = v
end)

script.Parent.Events.GD.OnInvoke = function(plr)
	return data[plr.Name]["rdata"]
end

4 comments

0

its nil tho

0

New player don't have any table (nil) Have you tried to check if the player is new and create the table for them?

0

i did,line 22-34

0

i found the cause on line 33, the nil table is set twice so all of the verification is useless, someone post an answer so i can flag this as answered