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

Is there any way to save something else than leaderstats?

Is there just any way to save a Folder containing many bool values with DataStore? (Something else than leaderstats, wow.) I've tried many codes but haven't gotten a result.

This is the last code i've used, at least i haven't gotten any errors but no results on it either.


local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore") local Stats = nil local Weps = nil local Foxes = nil

game.Players.PlayerAdded:connect(function(plr)

if plr:FindFirstChild("Stats") == nil then Stats = script.Stats:Clone() Stats.Parent = plr end if plr:FindFirstChild("UnlockedWeapons") == nil then Weps = script.UnlockedWeapons:Clone() Weps.Parent = plr end if plr:FindFirstChild("UnlockedFoxes") == nil then Foxes = script.UnlockedFoxes:Clone() Foxes.Parent = plr end

local key = "user-" .. plr.userId local storeditems = datastore:GetAsync(key) if storeditems then Stats = storeditems[1] --Value of the Points, change "points" if you changed line 10 Weps = storeditems[2] --Value of the Wins, change "wins" if you changed line 14 else local items = {Stats, Weps} --Change Points or Wins if you changed line 10 or 14 datastore:SetAsync(key, items) end end)

game.Players.PlayerRemoving:connect(function(player) local items = {Stats, Weps} --Change Points or Wins if you changed line 10 or 14 local key = "user-" .. player.userId

datastore:SetAsync(key, items)

end)

2 answers

Why yes there is! Roblox Wiki - Leaderboards(Exploiting)

The exploiting section has what you need. What you want is a table to store the player's data.

local playersData = {} 

local function printTable(myTable)
	for _,v in pairs(myTable) do
		print(v)
	end
end

game.Players.PlayerAdded:connect(function(Player)
	playersData[Player.UserId] = {}

	playersData[Player.UserId]["Stats"] = { str=0,int=5,dex=10}
	playersData[Player.UserId]["Pets"] = {"Cow","Bee","Rabbit"} 
	playersData[Player.UserId]["Weapon"] = {"Ragnarok","Caledfwich","Oathkeeper"}
	
	printTable(playersData[Player.UserId]["Stats"] )
	printTable(playersData[Player.UserId]["Pets"])
	printTable(playersData[Player.UserId]["Weapon"])
end)

You have a table that's unique for every player by using their UserId as the key. Then inside of that table you have more tables for what you need.

3 comments

0

Didn't really help.

0

Why doesn't it help? It saves your players data. Of course you have to integrate it with DataStore yourself though.

0

If you don't know how to make DataStore work the I'd recommend reading Data Store

If I'm understanding you correctly, you mean saving something else than leaderstats, like a value inside the player or maybe just a value in workspace.

I do not know if you want it to be a playersave (value inside the player) or serversave (value inside workspace or anyhing else than a player or a player char). I'll give you the answer for player as you already have a script with something like that.

You want to start with a playerAdded event and some starting variables

local DataStore = game:GetService("DataStoreService")
local PlayerSave = DataStore:GetDataStore('PlayerDataStore')

game.Players.PlayerAdded:connect(function(plr)
	-- code
end)

You probably already knew that but I want to make sure you know every part of the script.

Then you want to save the value, you should access the player stats first.

local stats = plr:WaitForChild('Stats')

If you want to create the stats folder however, you should use

local stats = Instance.new('Folder', plr)

I'll make it create a stats folder.

local DataStore = game:GetService("DataStoreService")
local PlayerSave = DataStore:GetDataStore('PlayerDataStore')

game.Players.PlayerAdded:connect(function(plr)

	local key = plr.UserId

	local stats = Instance.new('Folder',plr)
	stats.Name = 'Stats'
	
	local val1 = Instance.new('BoolValue',stats)
	val1.Name = 'Val1'

	local val2 = Instance.new('BoolValue',stats)
	val2.Name = 'Val2'

	local saves = PlayerSave:GetAsync(key) or {false,false} -- Or any value

	val1.Value = saves[1]
	val2.Value = saves[2]
	while wait(10) do

		local values = {val1.Value, val2.Value}	
		
		PlayerSave:SetAsync(plr, values)
	end
end)

I hope I didn't make any mistakes in that script, if I did, please say so. I could explain datastores completely to you but that would take a long time, I did make pretty detailed answers on datastore that describe it pretty good, you can read them here and here

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