Again Problem with datastore

Hmmm lemme check something… maybe this could be a solution

1 Like

Maybe i save too much datastores in one line???

I just removed those lines and a variable which contains stats path and now everything fine, problem is only with stats path

Okay, thats weird. But I hope you could find a solution to get stats path to work…

the heck
image

Nvm forgot to do the .value i just made a folder in player like leaderstats but stats

Do you have any instances in there, like a parent?

Yeah, that is what I thought it was. Good you found it

O i found a solution, i made a STATS folder with a script and everything works

1 Like

Okay cool. Finally a solution lol. Okay, well, still weird that it didn’t work before for you but it worked for me…

Lmao for some reason script do not create instances now and i get tons of error bruh

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = player
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local clicks = Instance.new("IntValue")
	clicks.Name = "Clicks"
	clicks.Parent = leaderstats

	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	
	local memory = Instance.new("IntValue")
	memory.Name = "Memory"
	memory.Parent = StatsFolder
	
	local memorylevel = Instance.new("IntValue")
	memory.Name = "MemoryLevel"
	memory.Parent = StatsFolder
	
	local mouselevel = Instance.new("IntValue")
	memory.Name = "MouseLevel"
	memory.Parent = StatsFolder
	
	local rcamount = Instance.new("IntValue")
	memory.Name = "RCAmount"
	memory.Parent = StatsFolder
	
	local rcmulti = Instance.new("NumberValue")
	memory.Name = "RCMulti"
	memory.Parent = StatsFolder

	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				clicks.Value = result[1]
				money.Value = result[2]
				rebirths.Value = result[3]	
				memory.Value = result[4]
				memorylevel.Value = result[5]
				mouselevel.Value = result[6]
				rcamount.Value = result[7]
				rcmulti.Value = result[8]
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMulti.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMulti.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

Lmao can’t get a problem in that thing only RCMULTI create and leaderstats creates, but everything must be fine…

Is there a result[8]? Otherwise it could be that or some other value