Attempt to concatenate string with nil

how can execute the local data part perfect for the async part without getting the error "attempt to concatenate string with nil "

local planetdata = game:GetService("DataStoreService"):GetDataStore("PlanetData")
local PlanetList,Planets,PlanetNames,GravityList = MainModule.PlanetList()
local RaceStats = MainModule.GetRaceStats()
local data = planetdata:GetAsync("test")
	if not data then	
		planetdata:SetAsync("test", {RaceStats[Stats.Race.Value]['Home Planet']..PlanetList[Planets]})
		wait(3)

The error means your code tries to add nil to a string.

Looking at your code, this probably happens with this expression:

RaceStats[Stats.Race.Value]['Home Planet']..PlanetList[Planets]

To solve your problem, I would recommend:

  1. Printing the two values in the expression above and see which one is nil
  2. Check why that value is nil
  3. If the value is intentionally nil, then add another check to your code (similar to if not data then)
  4. If the value is not intentionally nil, then you should solve that root problem
5 Likes

thats not the issue at all that code will run fine with player.UserId as the data but i wanna be able to change

“but I wanna be able to change” Change what?

3 Likes

That is causing the error unless you sent the wrong one.

Follow the steps above to solve your problem. Based on what you said, it sounds like your saved data is lacking an entry. Print out the data, find which part is missing, and check where that should have been added.