Datastore wont save 2 values

I have a datastore that stores hair and race values but for some reason it only saves the hair value

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("RaceData")
local HairDs = DataStore:GetDataStore("HairDataStore")

game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "Data"
	local Cash = Instance.new("StringValue",leader)
	Cash.Name = "Race"
	Cash.Value = ds:GetAsync(player.UserId) or "None"
	ds:SetAsync(player.UserId, Cash.Value)
	Cash.Changed:connect(function()
		ds:SetAsync(player.UserId, Cash.Value)	
	end)

	local HairData = Instance.new("NumberValue",leader)
	HairData.Name = "HairVal"
	HairData.Value = HairDs:GetAsync(player.UserId) or -1

	HairDs:SetAsync(player.UserId, HairData.Value)


	HairData.Changed:Connect(function()
		HairDs:SetAsync(player.UserId, HairData.Value)
	end)
end)




game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.Data.Race.Value) 
	HairDs:SetAsync(player.UserId, player.Data.HairVal.Value)
end)

in this clip I set my race to otsu but it wont save

1 Like

Really common problem among beginners.

If saving does not work in Studio but does work in the real game, then refer to this post:

1 Like

But it can save the hair value fine but not the race value which is why I think its a scripting error

1 Like

i found the error nvm!
aaaaaaaa

1 Like