every time a player joins, try to see if the player has data, if the player has data, set the key in PlayerSession to the player’s userid (player.UserId), if not then return the template
local serialized_data = ShikaiUnlockedData:GetAsync(player.UserId)
if serialized_data then
-- load the player data in
PlayerSession[player.UserId] = serialized_data
else
-- first time? return templete
PlayerSession[player.UserId] = ReturnTemplete()
end
then after, you’d set the data
local Data = PlayerSession[player.UserId]
ShikaiName.Value = Data.ShikaiName
make sure you also wrap datastore calls in a pcall, they can fail
local Ok,Data = pcall(function()
return ShikaiUnlockedData:GetAsync(player.UserId)
end)
if Ok then
-- Success
else
-- Fail
end
local HttpService = game:GetService("HttpService")
local DataStore = game:GetService("DataStoreService")
local ShikaiUnlockedData = DataStore:GetDataStore("ShikaiUnlockedData")
local function ReturnTemplete()
return {
["Unlocked"] = "NotUnlocked",
["Call"] = "Locked",
["ShikaiName"] = "Locked",
["WhatSword"] = "None",
}
end
local PlayerSession = {
-- [Player.UserId]
}
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "Data"
local Folder = Instance.new("Folder",leader)
Folder.Name = "ShikaiInfo"
local ShikaiName = Instance.new("StringValue",Folder)
ShikaiName.Name = "ShikaiName"
local serialized_data = ShikaiUnlockedData:GetAsync(player.UserId)
if serialized_data then
-- load the player data in
serialized_data = HttpService:JSONDecode(serialized_data)
PlayerSession[player.UserId] = serialized_data
else
-- first time? return templete
PlayerSession[player.UserId] = ReturnTemplete()
end
local Data = PlayerSession[player.UserId]
ShikaiName.Value = Data.ShikaiName
ShikaiName.Changed:Connect(function()
Data.ShikaiName = ShikaiName.Value
warn(Data)
local serialized = HttpService:JSONEncode(Data)
ShikaiUnlockedData:SetAsync(player.UserId,serialized)
print("SAVED")
end)
end)