Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

what is wrong with this script its not saving the eggs ?

Asked by 4 years ago

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)
0
what is player? (line 10) Did you ever define it? matiss112233 258 — 4y
0
It is defined on line 07 User#32519 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question