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

DataStore won't save data in Studio?

BEFORE I HAVE PEOPLE SHOUTING AT ME IN THE COMMANTS SAYING: YOU NEED TO HAVE STUDIO API ACSSES ENABLED... FORGET IT, I DO

Anyway, now I have sorted that out... The code below does not save the data, after changing the money amount from 100 to 1000, I reload the game, and it says 100... what else is there to say?

Save Data

game.Players.PlayerRemoving:connect(function(plr)
	-- Connect to DataStoreService
	local DataStoreService = game:GetService("DataStoreService")
	local GameData = DataStoreService:GetDataStore("TheMinesStats")
	local SuperAlphaCoins = DataStoreService:GetDataStore("Tokens")
	
	-- Save the DATA!	
	GameData:SetAsync(game.Players[plr.Name].UserId, {{game.Players[plr.Name].Stats.pickaxe.dur.Value, game.Players[plr.Name].Stats.pickaxe.twoside.Value, game.Players[plr.Name].Stats.pickaxe.typea.Value, game.Players[plr.Name].Stats.pickaxe.typeb.Value, game.Players[plr.Name].Stats.pickaxe.style.Value}, {game.Players[plr.Name].Stats.stuff.Stone.Value, game.Players[plr.Name].Stats.stuff.Coal.Value, game.Players[plr.Name].Stats.stuff.Copper.Value, game.Players[plr.Name].Stats.stuff.Iron.Value, game.Players[plr.Name].Stats.stuff.Diamond.Value, game.Players[plr.Name].Stats.stuff.Emarald.Value}, game.Players[plr.Name].Stats.money.MineCoins.Value, {game.Players[plr.Name].Stats.stats.StoneMined.Value, game.Players[plr.Name].Stats.stats.CoalMined.Value, game.Players[plr.Name].Stats.stats.CopperMined.Value, game.Players[plr.Name].Stats.stats.IronMined.Value, game.Players[plr.Name].Stats.stats.DiamondMined.Value, game.Players[plr.Name].Stats.stats.EmaraldMined.Value}})
	SuperAlphaCoins:SetAsync(game.Players[plr.Name].UserID, game.Players[plr.Name].Stats.money.SuperAlphaCoins.Value)		
	print("Data saved for " .. plr.name)
end)

Load Data

game.Players.PlayerAdded:connect(function(plr)	
	-- Connect to DataStoreService
	local DataStoreService = game:GetService("DataStoreService")
	local GameData = DataStoreService:GetDataStore("TheMinesStats")
	local SuperAlphaCoins = DataStoreService:GetDataStore("Tokens")
	
	-- Get Data
	local PlayerStats = GameData:GetAsync(game.Players[plr.Name].UserId)
	local TokanAmount = SuperAlphaCoins:GetAsync(game.Players[plr.Name].UserId)
	print(plr.Name .. "'s data has been loaded")
	
	-- Validate data
	if not PlayerStats then
		local PlayerStats = {{0, false, "", "", ""}, {0, 0, 0, 0, 0, 0}, 100, {0, 0, 0, 0, 0, 0}}
		GameData:SetAsync(game.Players[plr.Name].UserId, PlayerStats)
		print(plr.Name .. " has no data, they are a new user")
	end	
	
	if not TokanAmount then
		local TokanAmount = 100
		SuperAlphaCoins:SetAsync(game.Players[plr.Name].UserId, 100)
		print(plr.Name .. " has no Tokan data, they have never played a game by AlphaGamer150")
	end
	
	-- Sort data
	local pickaxedata = PlayerStats[1]
	local stuffdata = PlayerStats[2]
	local moneydata = PlayerStats[3]
	local statsdata = PlayerStats[4]
	
	-- Make Folders
	local Stats = Instance.new("Folder")
	Stats.Parent = plr
	Stats.Name = "Stats"
	
	local pickaxe = Instance.new("Folder")
	pickaxe.Parent = Stats
	pickaxe.Name = "pickaxe"
	
	local stuff = Instance.new("Folder")
	stuff.Parent = Stats
	stuff.Name = "stuff"
	
	local money = Instance.new("Folder")
	money.Parent = Stats
	money.Name = "money"
	
	local stats = Instance.new("Folder")
	stats.Parent = Stats
	stats.Name = "stats"
	
	-- Load pickaxe data
	local dur = Instance.new("IntValue")
	dur.Parent = pickaxe
	dur.Name = "dur"
	dur.Value = pickaxedata[1]
	
	local twoside = Instance.new("BoolValue")
	twoside.Parent = pickaxe
	twoside.Name = "twoside"
	twoside.Value = pickaxedata[2]
	
	local typea = Instance.new("StringValue")
	typea.Parent = pickaxe
	typea.Name = "typea"
	typea.Value = pickaxedata[3]
	
	local typeb = Instance.new("StringValue")
	typeb.Parent = pickaxe
	typeb.Name = "typeb"
	typeb.Value = pickaxedata[4]
	
	local style = Instance.new("StringValue")
	style.Parent = pickaxe
	style.Name = "style"
	style.Value = pickaxedata[5]
	
	-- Make note var to be used later on	
	local note = Instance.new("StringValue")
	note.Parent = Stats
	note.Name = "note"
	note.Value = "Welcome to The Mines"
	
	-- Load bag data
	local Stone = Instance.new("IntValue")
	Stone.Parent = stuff
	Stone.Name = "Stone"
	Stone.Value = stuffdata[1]
	
	local Coal = Instance.new("IntValue")
	Coal.Parent = stuff
	Coal.Name = "Coal"
	Coal.Value = stuffdata[2]
	
	local Copper = Instance.new("IntValue")
	Copper.Parent = stuff
	Copper.Name = "Copper"
	Copper.Value = stuffdata[3]
	
	local Iron = Instance.new("IntValue")
	Iron.Parent = stuff
	Iron.Name = "Iron"
	Iron.Value = stuffdata[4]
	
	local Diamond = Instance.new("IntValue")
	Diamond.Parent = stuff
	Diamond.Name = "Diamond"
	Diamond.Value = stuffdata[5]
	
	local Emarald = Instance.new("IntValue")
	Emarald.Parent = stuff
	Emarald.Name = "Emarald"
	Emarald.Value = stuffdata[6]
	
	-- Load money data
	local SuperAlphaCoins = Instance.new("IntValue")
	SuperAlphaCoins.Parent = money
	SuperAlphaCoins.Name = "SuperAlphaCoins"
	SuperAlphaCoins.Value = TokanAmount
	
	local MineCoins = Instance.new("IntValue")
	MineCoins.Parent = money
	MineCoins.Name = "MineCoins"
	MineCoins.Value = moneydata
	
	-- Load stats data
	local StoneMined = Instance.new("IntValue")
	StoneMined.Parent = stats
	StoneMined.Name = "StoneMined"
	StoneMined.Value = statsdata[1]
	
	local CoalMined = Instance.new("IntValue")
	CoalMined.Parent = stats
	CoalMined.Name = "CoalMined"
	CoalMined.Value = statsdata[2]
	
	local CopperMined = Instance.new("IntValue")
	CopperMined.Parent = stats
	CopperMined.Name = "CopperMined"
	CopperMined.Value = statsdata[3]
	
	local IronMined = Instance.new("IntValue")
	IronMined.Parent = stats
	IronMined.Name = "IronMined"
	IronMined.Value = statsdata[4]
	
	local DiamondMined = Instance.new("IntValue")
	DiamondMined.Parent = stats
	DiamondMined.Name = "DiamondMined"
	DiamondMined.Value = statsdata[5]
	
	local EmaraldMined = Instance.new("IntValue")
	EmaraldMined.Parent = stats
	EmaraldMined.Name = "EmaraldMined"
	EmaraldMined.Value = statsdata[6]
end)

2 answers

You can enable it from the game settings. On the game page, click the three dots, then click "Configure this GAME", then enable "Enable Studio Access to API Services"

Screenshot

4 comments

0

Can you read?

0

I said in the top in bold, capital lettered writing saying that I have it enabled

0

oh gg

0

sorry about that, i only paid attention to the title.

i dont think you can test it in studio, you actually have to play it with the roblox game client due to the map in studio being an offline copy

1 comment

0

This should be in a comment, not an anwser

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