I'm confounded, I really am. The output shows no errors. There's a folder in the player called "PlayerOptions" in my game with the rumble and physics values. The answer is probably really obvious and stupid, so I apologize in advance.

Through some experimenting, I narrowed the reason down to either the data table is never created or the values are never saved to the table.

PlayerClass is a string value, Winnings is a number value, Physics is a string value, and Rumble is a boolean value. Here's the script"

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Stats")


function onPlayerEntered(Player) 

	local Data = DataStore:GetAsync(Player.UserId) -- Get Data
	leaderstats = Player:WaitForChild("leaderstats")
	PlayerOptions = Player:WaitForChild("PlayerOptions")


	while true do 
		if Player.Character ~= nil then break end 
		wait(5)
	end 


	----leaderboard----
	local TotalWins = leaderstats.Winnings
	local classname =  leaderstats.PlayerClass

	----options----
	local Rumble = PlayerOptions.Rumble
	local Physics =  PlayerOptions.Physics



	if type(Data) ~= "table" then
		Data = nil
	end

	if Data then
		if Data.classname ~= nil then
			classname.Value = Data.classname end
		if Data.TotalWins ~= nil then
			TotalWins.Value = Data.TotalWins end

		if Data.Physics ~= nil then
			Physics.Value = Data.Physics end 
		if Data.Rumble ~= nil then
			Rumble = Data.Rumble end
	end
end

game.Players.ChildAdded:connect(onPlayerEntered)

game.Players.PlayerRemoving:Connect(function(Player) -- save function here

	--[{ DATA STORE SAVING }]--

	DataStore:SetAsync(Player.UserId, { -- gets data
		classname = leaderstats["PlayerClass"].Value,
		TotalWins = leaderstats["Winnings"].Value,

		Physics = PlayerOptions["Physics"].Value,
		Rumble = PlayerOptions["Rumble"].Value	
	})

end)

1 comment

0

I see you experimented but did you try to just print the datastore values yet? That tells you if they were saved or not.