Cause of death : datastore script

Yes Im bad at scripting and yes the code you will read is bad

So the problem here, The Career1 is being saved, but for example the Skill1 isnt being saved, and i dont know why
its either not being saved or not being loaded

But Career1 is being saved and loaded so idk whats the problem mate, I have been trying for 2 days

local dsService = game:GetService("DataStoreService")
local runservice = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(plr)
	local PlayerStats = Instance.new("Folder")
	PlayerStats.Name = 'CareerDataStores'
	PlayerStats.Parent = plr

	local Career1 = Instance.new("StringValue")
	Career1.Parent = PlayerStats
	Career1.Value = "nil"
	Career1.Name = 'Career1'
	
	local Iq1 = Instance.new("NumberValue")
	Iq1.Parent = Career1
	Iq1.Value = 0
	Iq1.Name = 'IQ_1'
	
	local Skill1 = Instance.new("NumberValue")
	Skill1.Parent = Career1
	Skill1.Value = 0
	Skill1.Name = 'Skill_1'
	
	local Fun1 = Instance.new("NumberValue")
	Fun1.Parent = Career1
	Fun1.Value = 0
	Fun1.Name = 'Fun_1'
-----------------------------------------------------------
	local function autosave()
		dsService:GetDataStore("Career"):SetAsync("Career1", Career1)
		dsService:GetDataStore("IQ1"):SetAsync(plr.UserId, Iq1.Value)
		dsService:GetDataStore("Skill1"):SetAsync(plr.UserId, Skill1.Value)
		dsService:GetDataStore("Fun1"):SetAsync(plr.UserId, Fun1.Value)
		print("SavedStats")
	end
	
	local CareerName
	local IQ1Value, Skill1Value, Fun1Value
	
	
	local success, errormessage = pcall(function()
		CareerName = dsService:GetDataStore("Career"):GetAsync(plr.UserId)
		IQ1Value =  dsService:GetDataStore("IQ1"):GetAsync(plr.UserId)
		Skill1Value = dsService:GetDataStore("Skill1"):GetAsync(plr.UserId)
		Fun1Value = dsService:GetDataStore("Fun1"):GetAsync(plr.UserId)
	end)
	
	if success then
		print("Success")
	else
		print("Nah ErrorMessage")
	end
	
	Career1.Changed:Connect(function(NewCurrentCareer)
		Career1 = NewCurrentCareer
		autosave()
	end)
	Iq1.Changed:Connect(function(NewIQ)
		Iq1 = NewIQ
		autosave()
	end)
	Skill1.Changed:Connect(function(NewSkill)
		Skill1 = NewSkill
		autosave()
	end)
	Fun1.Changed:Connect(function(NewFun)
		Fun1 = NewFun
		autosave()
	end)
	
	if game:GetService("DataStoreService"):GetDataStore("Career"):GetAsync("Career1") then
		Career1.Value = game:GetService("DataStoreService"):GetDataStore("Career"):GetAsync("Career1")		
		Skill1.Value = dsService:GetDataStore("Skill1"):GetAsync(plr.UserId) or 0
		--Fun1.Value = tonumber(game:GetService("DataStoreService"):GetDataStore("Career"):GetAsync("Fun_1")) or 0
		--Iq1.Value = tonumber(game:GetService("DataStoreService"):GetDataStore("Career"):GetAsync("IQ_1")) or 0
		print("what ever this line does it worked")
	end
end)

this block right here prints success :

	local success, errormessage = pcall(function()
		CareerName = dsService:GetDataStore("Career"):GetAsync(plr.UserId)
		IQ1Value =  dsService:GetDataStore("IQ1"):GetAsync(plr.UserId)
		Skill1Value = dsService:GetDataStore("Skill1"):GetAsync(plr.UserId)
		Fun1Value = dsService:GetDataStore("Fun1"):GetAsync(plr.UserId)
	end)
	
	if success then
		print("Success")
	else
		print("Nah ErrorMessage")
	end

Put all the values in a table and then save the table. When you use :SetAsync(), youre not adding another value to the player’s datastore. You are wiping it and then setting it to that new value.

you can do something like

data = {
Career = Career1,
IQ = Iq1.Value,
Skill1 = Skill1.Value,
Fun1 = Fun1.Value,
}

dsService:GetDataStore("Fun1"):SetAsync(plr.UserId, data)

When you get the data, you can loop through it like this

for name, value in pairs(data) do
      --for example, name will be IQ, value will be 130
end
1 Like

Kinda off topic, why did you not use camalCase for both of them!!! Also do you have any error messages?

1 Like

Update
I fixed it bruv and I dont like data stores