- ServerScriptService.Script:20: attempt to index nil with 'Save_see'?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I am trying to make a data store that saves a player’s clothing.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know why but the script breaks when I try assigning the data to something.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried searching up a solution but I couldn’t find anything.

local DataStoreService = game:GetService("DataStoreService")
local player_data = DataStoreService:GetDataStore("Player_Data")


game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "Leaderstats"
	leaderstats.Parent = player
	
	local playerUserID = "Player_"..player.UserId
	
	local data
	local success, errorMessage  = pcall(function()
		data = player_data:GetAsync(playerUserID)
	end)
	
	if success then
		print("There is data") -- breaks in the line after this
		player.PlayerGui:FindFirstChild("new_Catalog").Save_see.Folder.pant_1.Value = data
	else
		print("no data")
	end
	
end)


game.Players.PlayerRemoving:Connect(function(player)
	local playerUserID = "Player_"..player.UserId
	local Data = player.Leaderstats.Pants_1.Value
	
	local success, errormessage = pcall(function()
		player_data:SetAsync(playerUserID, Data)
	end)
	
	if success then
		print("saved")
	end
	
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Use :WaitForChild() like

player.PlayerGui:WaitForChild("new_Catalog"):WaitForChild("Save_see"):WaitForChild("Folder"):WaitForChild("pant_1").Value = data

And even better would be to change UI in client, using a RemoteEvent.

The error suggests that the “new_Catalog” doesn’t exist. If it isnt loaded in yet, try switching it to

player.PlayerGui:WaitForChild("new_Catalog").Save_see.Folder.pant_1.Value = data

That fixed something but now I am getting this error. [ServerScriptService.Script:20: bad argument #3 (string expected, got nil)]

The value Data would be nil, either it never got, or there was no data saved.

1 Like

Do you know how I would be able to fix that.