DataStore2 Help

Code

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DataStore2 = require(ServerScriptService.DataStore2)
--------------------------------------------------------------------------------

DataStore2.Combine("DATA1")

Players.PlayerAdded:Connect(function(player)
	local genderStore = DataStore2("gender", player)
	local playerNameStore = DataStore2("playerName", player)
	local agencyNameStore = DataStore2("agencyName", player)
	
	local characterSkinStore = DataStore2("characterSkin", player)
	
	local logoDesignStore = DataStore2("logoDesign", player)
	local logoBGColorStore = DataStore2("logoBGColor", player)
	local logoPrimaryColorStore = DataStore2("logoPrimaryColor", player)
	local logoSeoncdaryColorStore = DataStore2("logoSecondaryColor", player)

	local PlayerData = Instance.new("Folder")
	PlayerData.Name = "PlayerData"
	PlayerData.Parent = player

	local CharacterCreation = Instance.new("Folder")
	CharacterCreation.Name = "CharacterCreation"
	CharacterCreation.Parent = PlayerData

	local gender = Instance.new("StringValue")
	gender.Name = "Gender"
	gender.Value = genderStore:Get("None")
	gender.Parent = CharacterCreation

	local playerName = Instance.new("StringValue")
	playerName.Name = "PlayerName"
	playerName.Value = playerNameStore:Get("None")
	playerName.Parent = CharacterCreation

	local agencyName = Instance.new("StringValue")
	agencyName.Name = "AgencyName"
	agencyName.Value = agencyNameStore:Get("None")
	agencyName.Parent = CharacterCreation
	
	-- Character Creation
	local characterSkin = Instance.new("StringValue")
	characterSkin.Name = "SkinColorID"
	characterSkin.Value = characterSkinStore:Get("1")
	characterSkin.Parent = CharacterCreation

	-- Logo Creation
	local logoDesign = Instance.new("StringValue")
	logoDesign.Name = "LogoDesignID"
	logoDesign.Value = logoDesignStore:Get("1")
	logoDesign.Parent = CharacterCreation
	
	local logoBGColor = Instance.new("StringValue")
	logoBGColor.Name = "LogoBGColorID"
	logoBGColor.Value = logoBGColorStore:Get("180, 180, 180")
	logoBGColor.Parent = CharacterCreation
	
	local logoPrimaryColor = Instance.new("StringValue")
	logoPrimaryColor.Name = "LogoPrimaryColorID"
	logoPrimaryColor.Value = logoPrimaryColorStore:Get("255,255,255")
	logoPrimaryColor.Parent = CharacterCreation
	
	local logoSecondaryColor = Instance.new("StringValue")
	logoSecondaryColor.Name = "LogoSecondaryColorID"
	logoSecondaryColor.Value = logoSeoncdaryColorStore:Get("0,0,0")
	logoSecondaryColor.Parent = CharacterCreation
	
---- Update Functions -----------------------------------------------------
	genderStore:OnUpdate(function(newGender)
		gender.Value = newGender
	end)
	
	playerNameStore:OnUpdate(function(newPlayerName)
		playerName.Value = newPlayerName
	end)

	agencyNameStore:OnUpdate(function(newAgencyName)
		agencyName.Value = newAgencyName
	end)

	-- Character Creation
	characterSkinStore:OnUpdate(function(newCharacterSkin)
		characterSkin.Value = newCharacterSkin
	end)

	-- Logo Creation
	logoDesignStore:OnUpdate(function(newLogoDesign)
		logoDesign.Value = newLogoDesign
	end)
	
	logoBGColorStore:OnUpdate(function(newLogoBGColor)
		logoBGColor.Value = newLogoBGColor
	end)
	
	logoPrimaryColorStore:OnUpdate(function(newPrimaryColor)
		logoPrimaryColor.Value = newPrimaryColor
	end)
	
	logoSeoncdaryColorStore:OnUpdate(function(newSecondaryColor)
		logoSecondaryColor.Value = newSecondaryColor
	end)
end)

local SelectMale = ReplicatedStorage.CreationRemotes:WaitForChild("SelectMale")
local function SelectMaleGender(player)
	local genderStore = DataStore2("gender", player)
	genderStore:Set("Male")
end
SelectMale.OnServerEvent:Connect(SelectMaleGender)

local SelectFemale = ReplicatedStorage.CreationRemotes:WaitForChild("SelectFemale")
local function SelectFemaleGender(player)
	local genderStore = DataStore2("gender", player)
	genderStore:Set("Female")
end
SelectFemale.OnServerEvent:Connect(SelectFemaleGender)

local PlayerNameInput = ReplicatedStorage.CreationRemotes:WaitForChild("PlayerNameInput")
local function PlayersName(player, playerName)
	local playerNameStore = DataStore2("playerName", player)
	playerNameStore:Set(playerName)
end
PlayerNameInput.OnServerEvent:Connect(PlayersName)

local AgencyNameInput = ReplicatedStorage.CreationRemotes:WaitForChild("AgencyNameInput")
local function AgencysName(player, agencyName)
	local agencyNameStore = DataStore2("agencyName", player)
	agencyNameStore:Set(agencyName)
end
AgencyNameInput.OnServerEvent:Connect(AgencysName)

-- Character Creation
local CharacterSkinSelection = ReplicatedStorage.CreationRemotes:WaitForChild("CharacterSkinSelection")
local function CharactersSkin(player, currentSkinColorIndex)
	local characterSkinStore = DataStore2("characterSkin", player)
	characterSkinStore:Set(currentSkinColorIndex)
end
CharacterSkinSelection.OnServerEvent:Connect(CharactersSkin)

-- Logo Creation
local LogoDesignSelection = ReplicatedStorage.CreationRemotes:WaitForChild("LogoDesignSelection")
local function LogoDesign(player, currentLogoDesignIndex)
	local logoDesignStore = DataStore2("logoDesign", player)
	logoDesignStore:Set(currentLogoDesignIndex)
end
LogoDesignSelection.OnServerEvent:Connect(LogoDesign)

local LogoBGSelection = ReplicatedStorage.CreationRemotes:WaitForChild("LogoBGSelection")
local function LogoBGColor(player, color)
	local logoBGColorStore = DataStore2("logoBGColor", player)
	logoBGColorStore:Set(color)
end
LogoBGSelection.OnServerEvent:Connect(LogoBGColor)

local LogoPrimaryColorSelection = ReplicatedStorage.CreationRemotes:WaitForChild("LogoPrimaryColorSelection")
local function LogoPrimaryColor(player, color)
	local logoPrimaryColorStore = DataStore2("logoPrimaryColor", player)
	logoPrimaryColorStore:Set(color)
end
LogoPrimaryColorSelection.OnServerEvent:Connect(LogoPrimaryColor)

local LogoSecondaryColorSelection = ReplicatedStorage.CreationRemotes:WaitForChild("LogoSecondaryColorSelection")
local function LogoSecondaryColor(player, color)
	local logoSecondaryColorStore = DataStore2("logoSecondaryColor", player)
	logoSecondaryColorStore:Set(color)
end
LogoSecondaryColorSelection.OnServerEvent:Connect(LogoSecondaryColor)

Am I using DataStore2 correctly? Using a whole bunch of stores for each single variable I want to save seems wrong. On the DataStore2 website guide I cannot find an answer to this. If anyone knows what I should do please tell me.

You need to combine all the different keys into the DATA1 key, otherwise you’ll probably get rate limited which may cause the issue. If you try to view DATA1 in the current state it will just show as blank.

I can see that you made an attempt to combine them

DataStore2.Combine(“DATA1”)

However, you didn’t add the actual keys to the combine function.
e.g.

DataStore2.Combine("DATA1", "gender", "playerName", "agencyName", "characterSkin", 'etc.')

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.