local Datastoreservice = game:GetService("DataStoreService")
local datastore = Datastoreservice:GetDataStore("EggHunt")
local replicatedstorage = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(player) -- kid who joins the game
local eggsfolder = Instance.new("Folder")
eggsfolder.Name = "Eggs"
eggsfolder.Parent = player
local data
local success, errorMsg = pcall(function()
data = datastore:GetAsync("EggsData-"..player.UserId)
end)
if success and data then
for _, eggName in pairs(data) do
if replicatedstorage.eggs:FindFirstChild(eggName) then
local eggValue = Instance.new("BoolValue")
eggValue.Name = eggName
eggValue.Parent = eggsfolder
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local eggsTable = {}
for _, egg in pairs(player.Eggs:GetChildren()) do
table.insert(eggsTable,egg.Name)
print(egg.Name)
end
local success, errorMsg = pcall(function()
datastore:SetAysnc("EggsData-"..player.UserId,eggsTable)
end)
if success then
print("saved")
else
print("not saved")
end
end)
✓ ANSWER ACCEPTED
what is wrong with this script its not saving the eggs ?
1 answer
✓ Accepted answer
When you are reading the Data from the DataStore, it looks like you are expecting to receive a table of EggNames, which represent the Eggs the player has collected. When you write the data, however, you are attempting to write the BoolValues that lie in the Eggs folder straight to the DataStore, which is not possible at all.
You will need to change how you structure your saving function to look at all of the Eggs in the Eggs folder, see if their value is true, and then store the name of the egg (if the value is true) into a table.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
what is player? (line 10) Did you ever define it?
It is defined on line 07