DataStore issues

Hi!
I am right now making my Settings save. It isn’t saving, because I don’t see the “Saved!” message, I also don’t see the error message. What’s wrong ?
Thanks!

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {
		Time = plr:FindFirstChild("leaderstats").TIME.Value,
		Flex = plr:FindFirstChild("leaderstats").Flex_Points.Value,
		Rap = plr:GetAttribute("RapidLoad"),
		Themecolor = plr:FindFirstChild("ThemeColor").Value,
	}
	local success, whoops = pcall(function()
		ds:SetAsync("id_"..plr.UserId, data)
	end)

	if success then
		print("Data saved successfully!")
	else
		warn("An error occurred saving the data, more info: ", whoops)
	end
end)

while task.wait(60) do	
	for i, plr in pairs(game.Players:GetPlayers()) do
		local data = {
			Rapid = plr:FindFirstChild("Settings").RapidLoad.Value,
			Flex = plr:FindFirstChild("leaderstats").Flex_Points.Value,
			Rap = plr:GetAttribute("RapidLoad").Value,
			Themecolor = plr:WaitForChild("ThemeColor").Value,
		}
		local success, whoops = pcall(function()
			ds:SetAsync("id_"..plr.UserId.."_settings", data)
		end)

		if success then
			print("Settings saved successfully!")
		else
			warn("An error occurred saving the settings, more info: ", whoops)
		end
	end
end

The stream is here if you want to see a video, I’m retrying it over and over as of right now.

Thanks!

I think it’s because it runs after the player is removed so you can’t see if it errors or saves.

1 Like

It also should run every 60 seconds.

Just a warning but PlayerRemoving often (possibly always) doesn’t fire in Studio, although you mentioned the problem still persists even with a every 60 seconds attempt. I’ll take a look at that.

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {
		Time = plr:WaitForChild("leaderstats").TIME.Value,
		Flex = plr:WaitForChild("leaderstats").Flex_Points.Value,
		Rap = plr:GetAttribute("RapidLoad"),
		Themecolor = plr:WaitFirstChild("ThemeColor").Value,
	}
	local success, whoops = pcall(function()
		ds:SetAsync("id_"..plr.UserId, data)
	end)

	if success then
		print("Data saved successfully!")
	else
		warn("An error occurred saving the data, more info: ", whoops)
	end
end)

while task.wait(60) do	
	for i, plr in pairs(game.Players:GetPlayers()) do
		local data = {
			Rapid = plr:WaitForChild("Settings").RapidLoad.Value,
			Flex = plr:WaitForChild("leaderstats").Flex_Points.Value,
			Rap = plr:GetAttribute("RapidLoad").Value,
			Themecolor = plr:WaitForChild("ThemeColor").Value,
		}
		local success, whoops = pcall(function()
			ds:SetAsync("id_"..plr.UserId.."_settings", data)
		end)

		if success then
			print("Settings saved successfully!")
		else
			warn("An error occurred saving the settings, more info: ", whoops)
		end
	end
end

Does this change result in any “infinite yield” warnings in console? If it does then one or more of your references are to invalid instances which either don’t exist or don’t exist in the correct directory (location) specified.

image
well i’m an idiot, sec

Nah, that’s on me, I’ve edited my original reply, try now.

local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
local RunService = game:GetService("RunService")

local ButtonsNames = {
	["Black"] = "Black",
	["Red"] = "Red",
	["Pink"] = "Pink",
	["Green"] = "Green",
	["Blusish"] = "Blusish",
	["Orange"] = "Orange",
	["Lavender"] = "Lavender"
}

game.Players.PlayerAdded:Connect(function(plr)
	local plrkey = "id_"..plr.UserId.."_settings"
	local save1 = plr:WaitForChild("Settings"):WaitForChild("RapidLoad")
	local save2 = plr:WaitForChild("Settings"):WaitForChild("SomethingElse")
	local save3 = plr:WaitForChild("Settings"):WaitForChild("SomethingElse")
	local themeColor = plr:WaitForChild("ThemeColor")

	local data
	local success, whoops = pcall(function()
		data = ds:GetAsync(plrkey)
	end)

	if success and data then
		save1.Value = data.Time
		save2.Value = data.Flex
		save3.Value = data.Rap
		themeColor.Value = data.Themecolor
		game.ReplicatedStorage:WaitForChild("ThemeColor"):FireClient(plr,data.Themecolor)
		print("Loaded data to: ", plr.Name)
	else
		if not data then
			warn("The user has no data! more info: ", whoops)
		else
			plr:Kick("Data could not load, probably due to an error with Roblox.\nYou have been kicked to prevent damage to your data.")
		end
	end
end)

while task.wait(60) do	
	for i, plr in pairs(game.Players:GetPlayers()) do
		local data = {
			Rapid = plr:WaitForChild("Settings").RapidLoad.Value,
			Flex = plr:WaitForChild("leaderstats").Flex_Points.Value,
			Themecolor = plr:WaitForChild("ThemeColor").Value,
		}
		local success, whoops = pcall(function()
			ds:SetAsync("id_"..plr.UserId.."_settings", data)
		end)

		if success then
			print("Settings saved successfully!")
		else
			warn("An error occurred saving the settings, more info: ", whoops)
		end
	end
end

Nope. I get “Success!” but it isn’t saved.

warn("The user has no data! more info: ", whoops)

This is printing when the GetAsync() runs?

image
Dont ask about 37, dont know where I was going with that.

local success, whoops = pcall(function()
	data = ds:GetAsync(plrkey)
end)

What does this return? What happens if you print(data)?

		save1.Value = data.Time
		save2.Value = data.Flex
		save3.Value = data.Rap
		themeColor.Value = data.Themecolor
		local data = {
			Rapid = plr:WaitForChild("Settings").RapidLoad.Value,
			Flex = plr:WaitForChild("leaderstats").Flex_Points.Value,
			Themecolor = plr:WaitForChild("ThemeColor").Value,
		}

The table being stored has some different keys/fields than the keys/fields you’re attempting to access when loading the table.

Check if you have API enabled.

1 Like

I do.

Try testing it in the actual game sometimes it just doesn’t work in studio.

Same result there.

I don’t know why it isn’t working then

Can you send the whole script?

or is that it?

EDIT: Found it above

You’re missing the data.Time, like @Limited_Unique said above

I only need rapid atm.