Script doesnt save boolvalue datas

This script prints That it saved the data but it doesn’t, help (btw i allowed api)

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

game.Players.PlayerAdded:Connect(function(player)
	local Punchs = Instance.new("Folder", player)
	Punchs.Name = "Punchs"
	local Beginner = Instance.new("BoolValue", Punchs)
	Beginner.Name = "Beginner"
	Beginner.Value = false
	local Intermediate = Instance.new("BoolValue", Punchs)
	Intermediate.Name = "Intermediate"
	Intermediate.Value = false
	
	local data = DataStoreService:GetDataStore(tostring(player.UserId))
	local suc, err = pcall(function()
		data = DataStore:GetAsync(tostring(player.UserId))
		
	end)
	if suc then
		Beginner.Value = data.Value
		Intermediate.Value = data.Value
	else
		warn(err)
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local savetable = {
		player.Punchs.Beginner.Value,
		player.Punchs.Intermediate.Value
	}
	local suc, err = pcall(function()
		DataStore:SetAsync(tostring(player.UserId), savetable)
	end)
	if suc then
		print("saved bools")
	else
		warn(err)
	end
end)

Why are you creating separate data stores for each player? Data stores are meant to hold more than 1 player’s data. You should only create ONE data store and call GetAsync() with the key passed in the parameters of the function to retrieve a player’s data.

You are trying to index a key called "Value" in the data which is in the form of a table like how you save it:

… which is the reason why it can’t load the data.

The problem lies on loading it, not saving it. What you should do is index the respective data according to the index of the element. For example if you want to load the Beginner.Value data, you should index data[1] since the first index of the saved table is that value.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.