Hi all,

I'm new to using DataStoreService. I'm having an issue where I'm unable to set a StringValue's Value to the data loaded from a DataStore. I'm probably being exceedingly stupid here, but I can't figure it out. The function is being called correctly via pcall at the end of the definition.

coroutine.resume(coroutine.create(function ()
	game.Players.PlayerAdded:connect(function(player)
	
	local function getData()
	local uid = player.UserId
	local DataStoreService = game:GetService("DataStoreService")
	local FirstName = DataStoreService:GetDataStore("FirstName")
	local LastName = DataStoreService:GetDataStore("LastName")
	local dobs = DataStoreService:GetDataStore("DOBs")
	local charSlot1 = DataStoreService:GetDataStore("Char1")
	fstr = FirstName:GetAsync(uid)
	
	local cg = Instance.new("BoolValue")
	cg.Parent = player
	cg.Name = "hasChar"
	cg.Value = charSlot1:GetAsync(uid) --this works
	
	local g = Instance.new("StringValue")
	g.Parent = player
	g.Name = "fname"
	g.Value = fstr --and this doesnt?

Output: http://prntscr.com/iif5cy

Any help would be greatly appreciated.

4 comments

0

this is saying that your FirstName variable is not returning anything. The player's id (uid) I suppose is a key in the datastore, but you have not set a value to that key.

0

@Legoman How can I catch this error so it will load something like "Blank" if there's nothing to load?

0

g.Value = fstr or "Blank" . This will make it "Blank" if fstr doesn't exist

0

You should not be getting a new data store for each value you are trying to save