Why does my data not store?

Maybe that should stay pairs … think ipairs is correct there.
If it’s retrying for each them it might be taking too long.

1 Like

weird, now it gives me an infinite yield warning for a LOT of my scripts: "Infinite yield possible on ‘Players.GagaGamesOfficial:WaitForChild(“leaderstats”)’:

ya you can’t do that trick if you have other scripts waiting on them directories.
would have to make them then task.wait a bit.

script makes directories and also loads/saves data

alright, ill try right now, but ill have to put the task.wait() the same way as the script?

post the script you have now …

yeah this definitely wouldn’t work, since the game needs to be loaded asap. any other alternatives?

Make your game so it don’t need to be loaded asap … idk. That’s what I do.
I use one that waits 30 seconds for player data then wait 30 more to load pets.

i got a new error for some reason: “21:56:09.272 ServerScriptService.Scripts.StagesData:111: attempt to index number with ‘StageV’ - Server - StagesData:111”

need to see where you are … can you post the script

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

local StageDS = DataStoreService:GetOrderedDataStore("Stage")

local function PlayerJoined(Player)
	local StatsF = Instance.new("Folder", Player)
	StatsF.Name = "leaderstats"

	local StageV = Instance.new("IntValue", StatsF)
	StageV.Name = "Stage"
	StageV.Value = 0
	
	local Rebirths = Instance.new("IntValue", StatsF)
	Rebirths.Name = "Rebirths"
	Rebirths.Value = 0

	local Data = StageDS:GetAsync(Player.UserId)
	if Data then
		StageV.Value = Data.StageV
		Rebirths.Value = Data.Rebirths
	end
end

local function PlayerLeft(Player)
	local StatsF = Player:FindFirstChild("leaderstats")
	if StatsF then
		local StageV = StatsF:FindFirstChild("Stage")
		if StageV then
			StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
		end
	end
end

Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)

game:BindToClose(function()
	for _, Player in ipairs(Players:GetPlayers()) do PlayerLeft(Player) end
end)```
Tries
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local StageDS = DataStoreService:GetOrderedDataStore("Stage")

local function PlayerJoined(Player)
	local StatsF = Instance.new("Folder", Player)
	StatsF.Name = "leaderstats"

	local StageV = Instance.new("IntValue", StatsF)
	StageV.Name = "Stage"
	StageV.Value = 0

	local Rebirths = Instance.new("IntValue", StatsF)
	Rebirths.Name = "Rebirths"
	Rebirths.Value = 0

	local StageC = Instance.new("IntValue", StatsF)
	StageC.Name = "Current_Stage"
	StageC.Value = 0

    task.wait(2)
	local function Try()
		local Tries = 0
		Tries = Tries + 1
		print("Try ("..Tries..") to load ("..Player.Name..") Stats!")

		local Success, Error = pcall(function()
			local Get = StageDS:GetAsync(Player.UserId)

			StageV.Value = Get.StageV
			StageC.Value = Get.StageV
			Rebirths.Value = Get.Rebirths
		end)

		if Success then
			print("Success loading ("..Player.Name..") Stats!")
			StatsF.Parent = Player
		else
			if Tries <= 10 then
				Try()
			else
				print("Error loading ("..Player.Name..") Stats!")
				Player:Kick("Failed to load Stats!")
			end
		end
	end
	Try()
end

local function PlayerLeft(Player)
	local StatsF = Player:FindFirstChild("leaderstats")
	if StatsF then
		local StageV = StatsF:FindFirstChild("Stage")
		if StageV then
			local function Try()
				local Tries = 0
				Tries = Tries + 1
				print("Try ("..Tries..") to save ("..Player.Name..") Stats!")

				local Success, Error = pcall(function()
					StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
				end)

				if Success then
					print("Success saving ("..Player.Name..") Stats!")
					StatsF.Parent = Player
				else
					if Tries <= 10 then
						Try()
					else
						print("Error saving ("..Player.Name..") Stats!")
					end
				end
			end
			Try()
		end
	end
end

Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)

game:BindToClose(function()
	for _, Player in ipairs(Players:GetPlayers()) do
		PlayerLeft(Player)
	end
end)

Once
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local StageDS = DataStoreService:GetOrderedDataStore("Stage")

local function PlayerJoined(Player)
    local StatsF = Instance.new("Folder", Player)
    StatsF.Name = "leaderstats"

    local StageV = Instance.new("IntValue", StatsF)
    StageV.Name = "Stage"
    StageV.Value = 0

    local Rebirths = Instance.new("IntValue", StatsF)
    Rebirths.Name = "Rebirths"
    Rebirths.Value = 0

    task.wait(2)
    local Data = StageDS:GetAsync(Player.UserId)
    if Data then
        StageV.Value = Data.StageV
        Rebirths.Value = Data.Rebirths
    end
end

local function PlayerLeft(Player)
    local StatsF = Player:FindFirstChild("leaderstats")
    if StatsF then
        local StageV = StatsF:FindFirstChild("Stage")
        if StageV then
            StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
        end
    end
end

Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)

game:BindToClose(function()
    for _, Player in ipairs(Players:GetPlayers()) do PlayerLeft(Player) end
end)

For tries:
Screen Shot 2024-02-10 at 10.11.11 PM

jesus christ…

For once:


Jezz, how about no saving for this game?
I yield, you’ll need someone to do this in the studio for real and be able to test it as they go.

Try converting the table to a JSON string before storing it, decode it back into a table when reading the table off the DataStore. Should fix the ValueNotAllowed error.

2 Likes

This may help …
save player game data

2 Likes

its… an obby game. the players data NEEDS to be saved for them to come back.

1 Like

I was kidding. That tutorial really looks up to date. It has everything anyone would need to know in full. I’ll be doing that today myself. Was hoping to give you a quick fix. I have helped so many of these I have a few dozen saved programs I’ll never use. Tring to avoid more. I should have posted a tutorial right away.

1 Like

Fixed the issue of the player’s data not loading, but now that opens up 2 brand new shiny issues that are for a completely different topic.

New problems are new questions.
Did you see this thread? same datastore as yours. I made a tested attempt at it.

1 Like

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