[UNSOLVED] Loading multiple StringValues when the player joins

Hi, I was wondering if I could load string values when the player is added

My current script:

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local keybinds = ReplicatedStorage:WaitForChild("Keybinds")







local function create_table()

	local player_stats = {}

	for _, stat in pairs(keybinds.Shoot:GetChildren()) do

		player_stats[stat.Name] = stat.Value

	end

	return player_stats

end



local function onPlayerExit(player) 



	local player_stats = create_table(player)

	local success, err = pcall(function()

		local playerUserId = "Player_" .. player.UserId

		DataStore:SetAsync(playerUserId, player_stats) 

	end)



	if not success then

		warn('Could not save data!')

	end

end
game.Players.PlayerRemoving:Connect(onPlayerExit)

Any help would be appreciated, thanks!

1 Like

You need to use :GetAsync to loads something that are saved.

1 Like

Use player added then use get async to load the string values that were saved?

Yes you need to do it like that.

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local keybinds = ReplicatedStorage:WaitForChild("Keybinds")




local function onPlayerAdded(player)
	local data
	
	local success , err = pcall(function()
		data = DataStore:GetAsync("Player_" .. player.UserId)
	end)
	
	if success then
		warn('Loaded data for player: ' .. player.Name)
	elseif not success then
		warn('Loading data for player: ' .. player.Name .. " has failed!")
	end
end


local function create_table()

	local player_stats = {}

	for _, stat in pairs(keybinds.Shoot:GetChildren()) do

		player_stats[stat.Name] = stat.Value

	end

	return player_stats

end



local function onPlayerExit(player) 



	local player_stats = create_table(player)

	local success, err = pcall(function()

		local playerUserId = "Player_" .. player.UserId

		DataStore:SetAsync(playerUserId, player_stats) 

	end)



	if success then

		warn('Saved data for player: ' .. player.Name)
	elseif not success then
		warn('Saving data for player: ' .. player.Name .. " has failed!")

	end

end



game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerExit)

But when I change one of the string values, it successfully saves but doesn’t load the players data

maybe try to change local data to local data = {}

and can you try to print the data that loaded using for i v loop?

Ok, I will try this.
char limitations

Yeah, It doesn’t work.
char limitations