Datastore Not storing two varibles

Good day,
I am trying my hand at datastore and the values are storing. i remove the dataB code and it stores then. So if i want another set of data save i have to make a new script?? for dataB?

local DataStoreService = game:GetService("DataStoreService")

local mydata = DataStoreService:GetDataStore("mydata")

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("IntValue",player)
	leaderstats.Name = "leaderstats"
	
	local cross = Instance.new("IntValue",leaderstats)
	cross.Name = "Crossings"
	
		
	local play = Instance.new("IntValue",leaderstats)
	play.Name = "GameTime"
	
	
	local data
	local dataB
	
	
	local success, errormessage = pcall(function()
		data = mydata:GetAsync(player.UserId.."-crossing",player.leaderstats.Crossings.Value)
		dataB = mydata:GetAsync(player.UserId.."-gametime",player.leaderstats.GameTime.Value)
	end)
	
	
	if success then
		cross.Value = data
		play.Value = dataB
	
	else
		print("error error")
		warn(errormessage)
	end
	
	
end)


game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		mydata:SetAsync(player.UserId.."-crossing",player.leaderstats.Crossings.Value)
		mydata:GetAsync(player.UserId.."-gametime",player.leaderstats.GameTime.Value)
	end)
	
	
	if success then
		print("player data save success!")
	else
		print("error error")
		warn(errormessage)
	end
	
end)

uhm, i think you did an error there.
you are not setting the second value (gametime), you are getting it
image

2 Likes

Wow, I cant believe i that G, i been looking at this code for past 1hr and didnt see it.

1 Like