Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't DataStore not loading nor saving the values it contained?

So basically I've made a DataStore containing 4 values but it didn't load nor save those 4 values it contained and I swear the last time I've made a DataStore containing more than 1 values worked! But this time it didn't! Please check my script.

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

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder",Player)
	Leaderstats.Name = "Leaderstats"
	
	local Coins = Instance.new("IntValue",Leaderstats)
	Coins.Name = "Coins"
	
	local Written = Instance.new("IntValue",Leaderstats)
	Written.Name = "Written"
	
	local Gems = Instance.new("IntValue",Leaderstats)
	Gems.Name = "Gems"
	
	local Restarts = Instance.new("IntValue",Leaderstats)
	Restarts.Name = "Restarts"
	
	local LoadedCoins = 0
	local LoadedWritten = 0
	local LoadedGems = 0
	local LoadedRestarts = 0
	
	local Success,Failed = pcall(function()
		LoadedCoins = DataStore:GetAsync(Player.UserId.."Coins")
		LoadedWritten = DataStore:GetAsync(Player.UserId.."Written")
		LoadedGems = DataStore:GetAsync(Player.UserId.."Gems")
		LoadedRestarts = DataStore:GetAsync(Player.UserId.."Restarts")
	end)
	
	if Success then
		Coins.Value = LoadedCoins
		Written.Value = LoadedWritten
		Gems.Value = LoadedGems
		Restarts.Value = LoadedRestarts
	else
		warn(Failed)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Success,Failed = pcall(function()
		DataStore:SetAsync(Player.UserId.."Coins",Player.Leaderstats.Coins.Value)
		DataStore:SetAsync(Player.UserId.."Written",Player.Leaderstats.Written.Value)
		DataStore:SetAsync(Player.UserId.."Gems",Player.Leaderstats.Gems.Value)
		DataStore:SetAsync(Player.UserId.."Restarts",Player.Leaderstats.Restarts.Value)
	end)
	
	if Success then
		print("Successfully saved "..Player.Name.."'s data!")
	else
		warn(Failed)
	end
	
end)

2 comments

0

You should test the script in real-game. DataStore not working properly inside studio.

0

IT WORKED! THANK YOU VERY MUCH! I PLAYED MY GAME IN ROBLOX PLAYER AND IT WORKED! I thought I have to debug my script!

1 answer

✓ Accepted answer

If your trying to see if its saving and loading in Roblox Studio, It will only load It can't save in Roblox Studio. Try in a regular server. Or see if you have not turned on API Serivces.

Using Data Stores in Studio DataStoreService cannot be used in Studio if a game is not configured to allow access to API services. See the Data Stores article for instructions.

DataStoreService

3 comments

0

WOW! THANK YOU SO MUCH!!! WHEN I PLAYED MY GAME IT SAVED ALL THOSE VALUES IT CONTAINED!

0

Your welcome! I also had the same problem like you 3 years ago but now I'm an experienced scripter! You can too, just learn more!

0

well, I'm happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.