Alvinblox egg hunt datastore not working

Im following @Alvin_Blox’s Egg Hunt Datastore tutorial.


and ran into this error:

ERROR:``

image

Code:

local DataStoreService = game:GetService(“DataStoreService”)

local DataStore = DataStoreService:GetDataStore(“EggHunt”)

game.Players.PlayerAdded:Connect(function(player)

local eggsFolder = Instance.new("Folder")
eggsFolder.Name = "Eggs"
eggsFolder.Parent = player

local data

local success, errorMsg = pcall(function()
	data = DataStore:GetAsync("EggData-"..player.UserId)
	
end)
if success and data then --{"EggName", "EggName"}
	for _, EggName in pairs(data) do
		if game.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 eggTable = {}

for _, egg in pairs(player.Eggs:GetChildren()) do
	
	
	table.insert(eggTable,egg.Name)
	print(egg.Name)
	end

local success, errorMsg = pcall(function()
	DataStore:SetAsync("EggData-"..player.UserId,eggTable)
end)

if success then
	print("Saved!")
else
	print(errorMsg)
end

end)

game:BindToClose(function(player)
for _, egg in pairs(game.Players:GetPlayers()) do
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:SetAsync("EggData-"..player.UserId,eggsTable)
	end)
	
	if success then print("Saved on BTC"..player.Name) end
	
end

end)

Can you format it properly please? It’d make it easier to read and to help as I need to look for line 59.

1 Like