I have looked at videos and got it to work to an extent, it saves the data that is within the folder but I have noticed that when you scan one object and you leave, once you rejoin and it will make both values true even though the one you scanned should be the only value that is true and the other should remain false until you scan it.
local Players = game.Players
local DataStore = game:GetService("DataStoreService")
local playerDataStore = DataStore:GetDataStore("pkeData")
local Scannable = script.Scannable
local ScanabbleData = Scannable:Clone()
local function playerJoin(Player)
ScanabbleData.Parent = Player
local playerID = Player.UserId
local pkeData = playerDataStore:GetAsync(playerID)
if pkeData then
for _, pkeScan in pairs(ScanabbleData:GetChildren()) do
pkeScan.Value = pkeData
end
end
end
local function createTables(Player)
local pkeStats = {}
for _, pkeData in pairs(ScanabbleData:GetChildren()) do
pkeStats[pkeData.Name] = pkeData.Value
end
return pkeStats
end
local function playerLeave(Player)
local pkeStats = createTables(Player)
local Success, Error = pcall(function()
local playerID = Player.UserId
playerDataStore:SetAsync(playerID, pkeStats)
end)
if not Success then
warn('Scans not saved!')
else
print('Scans saved!')
end
end
game.Players.PlayerAdded:Connect(playerJoin)
game.Players.PlayerRemoving:Connect(playerLeave)