Datastore not saving

You sure? It should’ve worked.

You can try his as well. Unless you put my script anywhere other than Workspace or ServerScriptService, then I don’t know

Do you think it’s my studio?.. I don’t know wgy

You use data stores in your game, not Studio

Bro. Use it

local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local Players = game.Players

local database = DataStoreService:GetDataStore("data")
local sessionData = {}

local function PlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = leaderstats

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

	local success = nil
	local PlayerData = nil
	local attempt = 1

	repeat 
		success,PlayerData = pcall(function()
			return database:GetAsync(player.UserId) 
		end)

		attempt += 1

		if not success then
			warn(PlayerData)
			task.wait(3)
		end
	until success or attempt == 5

	if success then
		print("Connected to database")
		if not PlayerData then
			print("Assigning default data")
			PlayerData = {
				["Money"] = 0;
				["Subscribers"] = 0;
			}	
		end
		sessionData[player.UserId] = PlayerData
	else
		warn("Unable to get data for "..player.UserId)
		player:Kick("Unable to load your data. Try again later")

	end

	--Character 1
	
	Money.Value = sessionData[player.UserId].Money
	Money.Changed:Connect(function()
		sessionData[player.UserId].Money = Money.Value
	end)
	
	Subscribers.Value = sessionData[player.UserId].Subscribers
	Subscribers.Changed:Connect(function()
		sessionData[player.UserId].Subscribers = Subscribers.Value
	end)
end

local function Save(player)
	if sessionData[player.UserId] then
		local success = nil
		local errorMsg = nil
		local attempt = 1

		repeat 
			success,errorMsg = pcall(function()
				database:SetAsync(player.UserId, sessionData[player.UserId]) 
			end)

			attempt += 1

			if not success then
				warn(errorMsg)
				task.wait(3)
			end
		until success or attempt == 5

		if success then
			print("Data saved for "..player.Name)
		else
			warn("Unable to save for ".. player.Name)
		end
	end
end

local function ServerShutdown()
	if RunService:IsStudio() then
		return
	end

	print("Server hutting down...")
	for i, player in ipairs(Players:GetPlayers()) do
		task.spawn(function()
			Save(player)
		end)

	end
end


Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(Save)
game:BindToClose(ServerShutdown)















--game:BindToClose(function(player)
--for i, player in pairs(game.Players:GetChildren()) do
--Save(player)
--end
--end)

ohearawesfservdtvgrtbdfgbrtfyrt

No difference. Both should be working

Dang bro chill i just added it :skull:

Xddddddddddddddddddddddddddddd
JUST CATCH IIT

What does catch it mean??? My brain brok

I think i give up. Can someone else hop in studio and test trying it

sameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

.
.
.

I’m going to test it. Btw, how you check if datastore is working?

Buggy’s script is in serverscriptservice and I just put Puzzled script in replicatedstorage

Mine’s supposed to be in ServerScriptService or workspace. I told you that already

Join so I can rank you so you can join my studio
AStro

Mine already works, you are supposed to insert it into ServerScriptService or Workspace

Ik I did put it in serverscriptservice but I put it in replicated to test it

It just wasn’t working in serverscriptservice

Actuallllyyyyyyyyyyyyyyyyyyyyyyy requested