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

My data works, but I want to be able to add new Values and save them aswell. How will I do this?

My script is

--// Services \\--
local players = game:GetService("Players");
local DataStoreService = game:GetService("DataStoreService");

--// Global Values \\--
PlayerData = {};
_G["Information"] = {
	Version = 1.03,
	ServerCreated = os.time(),
};
_G["JackpotData"] = {
	JackpotTimer = 100,	
};

--// DataTypes \\--
local MetaData = {};
MetaData.__index = MetaData
local GameData = DataStoreService:GetDataStore("KudoE_Data_15")

--// PresetTables \\--
local ValueSets = {
	Kudos = 0,
	Level = 0,
	XPNeeded = 100,
	XP = 0,
	Cases = 1,
	RebirthMultiplyer = 1,
	CostTix = 1,
	SuperKudos = 0, 
	FirstTime = 0,
	OG = {
		Title = "OG",
		Have = false,
		Color = 170, 0, 127,
	},
	Release = {
		Title = "Release",
		Have = false,
		Color = 255, 0, 0,
	},
	Common = {
		Title = "Common",
		Have = false,
		Color = 85, 255, 0,
	},
	Uncommon = {
		Title = "Uncommon",
		Have = false,
		Color = 85, 255, 255,
	},
	Cherry = {
		Title = "Cherry",
		Have = false,
		Color = 255, 0, 255
	},
	EssenceAmount = 0,
	Music1 = {
		Name = "BTS - Dynamite",
		Value = 500000,
		Own = false,
		Id = 5597073660,
	},	
	Music2 = {
		Name = "Come and Go - Juice WRLD",
		Value = 780000,
		Own = false,
		Id = 5341266037,
	},
	Music3 = {
		Name = "Empty (feat. BoyinaBand and Jaiden)",
		Value = 750000,
		Own = false,
		Id = 3364510397,
	},
	Music4 = {
		Name = "Minecraft OST - Pigstep (FlyxTheKid Remix)",
		Value = 1400000,
		Own = false,
		Id = 5763169040,
	},
	Music5 = {
		Name = "OOFER GANG - LIL PUMP",
		Value = 1650000,
		Own = false,
		Id = 1327560343,
	},
	Music6 = {
		Name = "XXXTentacion - Jocelyn Flores",
		Value = 2000000,
		Own = false,
		Id = 2495351392,
	},
	Multiplier = 1,
	World1 = {
		Name = "Mint World",
		Value = 1000000,
		Own = false,
	},
	World2 = {
		Name = "Cherry World",
		Value = 9500000,
		Own = false,
	},
	World3 = {
		Name = "Rainbow World",
		Value = 75000000,
		Own = false
	},
	Code1 = {
		Name = "Release",
		Acquired = false,
		Expired = false,
	},
	Code2 = {
		Name = "KudoClickerBest",
		Acquired = false,
		Expired = false,
	},
	OneVOneValues = {
		Added = 0,
		Total = 0,
		Gui1 = 0,
		Gui2 = 0,
		Time = 60,
		Player = "",
	},
	ItemValues = {
		RAP = 0,
		ItemNum = 0,
		IdYouGot = 0,
		YouGot = "",
		YouGotRAP = 0,
		Cases = 1,
	},
};

function MetaData:Join(player)
	local pdata = {
	Kudos = 0,
	Level = 0,
	XPNeeded = 100,
	XP = 0,
	Cases = 1,
	RebirthMultiplyer = 1,
	CostTix = 1,
	SuperKudos = 0, 
	FirstTime = 0,
		OG = {
			Title = "OG",
			Have = false,
			Color = 170, 0, 127,
		},
		Release = {
			Title = "Release",
			Have = false,
			Color = 255, 0, 0,
		},
		Common = {
			Title = "Common",
			Have = false,
			Color = 85, 255, 0,
		},
		Uncommon = {
			Title = "Uncommon",
			Have = false,
			Color = 85, 255, 255,
		},
		Cherry = {
			Title = "Cherry",
			Have = false,
			Color = 255, 0, 255
		},
	EssenceAmount = 0,
	Music1 = {
		Name = "BTS - Dynamite",
		Value = 500000,
		Own = false,
		Id = 5597073660,
	},	
	Music2 = {
		Name = "Come and Go - Juice WRLD",
		Value = 780000,
		Own = false,
		Id = 5341266037,
	},
	Music3 = {
		Name = "Empty (feat. BoyinaBand and Jaiden)",
		Value = 750000,
		Own = false,
		Id = 3364510397,
	},
	Music4 = {
		Name = "Minecraft OST - Pigstep (FlyxTheKid Remix)",
		Value = 1400000,
		Own = false,
		Id = 5763169040,
	},
	Music5 = {
		Name = "OOFER GANG - LIL PUMP",
		Value = 1650000,
		Own = false,
		Id = 1327560343,
	},
	Music6 = {
		Name = "XXXTentacion - Jocelyn Flores",
		Value = 2000000,
		Own = false,
		Id = 2495351392,
	},
	Multiplier = 1,
	World1 = {
		Name = "Mint World",
		Value = 1000000,
		Own = false,
	},
	World2 = {
		Name = "Cherry World",
		Value = 9500000,
		Own = false,
	},
	World3 = {
		Name = "Rainbow World",
		Value = 75000000,
		Own = false
	},
	Code1 = {
		Name = "Release",
		Acquired = false,
		Expired = false,
	},
	Code2 = {
		Name = "KudoClickerBest",
		Acquired = false,
		Expired = false,
	},
	OneVOneValues = {
		Added = 0,
		Total = 0,
		Gui1 = 0,
		Gui2 = 0,
		Time = 60,
		Player = "",
	},
	ItemValues = {
		RAP = 0,
		ItemNum = 0,
		IdYouGot = 0,
		YouGot = "",
		YouGotRAP = 0,
		Cases = 1,
		},
	};
	
	
local data = GameData:GetAsync(player.UserId)	
	
	if data then
	PlayerData[player.UserId] = data
    else
	PlayerData[player.UserId] = pdata
end	
end

Lets say I wanted to add new values, such as new currencies how would I add them to the data? I don't want to make a script if not [data] then PlayerData[player.UserId][data] = {}. I want it to automatically add it with this script. If you need more information I will give it

1 comment

0

What value do you want to add

1 answer

You can add multiple values into the datastore by concatenating multiple values into one value and separating them with a character:

playerData:SetAsync(playerUserId, value .. "+" .. value2)

Then you can seperate them with this:

newdata = string.split(data, '+') newval1 = newdata[1] newval2 = newdata[2]

1 comment

0

He already has a datastore system...

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