local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
shared.CookieCount = 0
game.Players.PlayerAdded:Connect(function(player)
local Original
local UFO
local OOB
local Bacon
local Sandstone
local Burnt
local Cactus
local CF
local Tiny
local success, errormessage = pcall(function()
Original = myDataStore:GetAsync(player.UserId.."-OriginalCookie")
UFO = myDataStore:GetAsync(player.UserId.."-UFOCookie")
OOB = myDataStore:GetAsync(player.UserId.."-OOBCookie")
Bacon = myDataStore:GetAsync(player.UserId.."-BaconCookie")
Sandstone = myDataStore:GetAsync(player.UserId.."-SandstoneCookie")
Burnt = myDataStore:GetAsync(player.UserId.."-BurntCookie")
Cactus = myDataStore:GetAsync(player.UserId.."-CactusCookie")
CF = myDataStore:GetAsync(player.UserId.."-CFCookie")
Tiny = myDataStore:GetAsync(player.UserId.."-TinyCookie")
end)
if success then
shared.OriginalCookie = Original
shared.UFOCookie = UFO
shared.OOBCookie = OOB
shared.BaconCookie = Bacon
shared.SandstoneCookie = Sandstone
shared.BurntCookie = Burnt
shared.CactusCookie = Cactus
shared.CFCookie = CF
shared.TinyCookie = Tiny
if shared.OriginalCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.UFOCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.OOBCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.BaconCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.SandstoneCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.BurntCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.CactusCookie then
shared.CookieCount = shared.CookieCount+1
wait()
elseif shared.CFCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
if shared.TinyCookie then
shared.CookieCount = shared.CookieCount+1
wait()
end
else
warn(errormessage)
if Original == nil then
shared.OriginalCookie = false
end
if UFO == nil then
shared.UFOCookie = false
end
if OOB == nil then
shared.OOBCookie = false
end
if Bacon == nil then
shared.BaconCookie = false
end
if Sandstone == nil then
shared.SandstoneCookie = false
end
if Burnt == nil then
shared.BurntCookie = false
end
if Cactus == nil then
shared.CactusCookie = false
end
if CF == nil then
shared.CFCookie = false
end
if Tiny == nil then
shared.TinyCookie = false
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-OriginalCookie",shared.OriginalCookie)
myDataStore:SetAsync(player.UserId.."-UFOCookie",shared.UFOCookie)
myDataStore:SetAsync(player.UserId.."-OOBCookie",shared.OOBCookie)
myDataStore:SetAsync(player.UserId.."-BaconCookie",shared.BaconCookie)
myDataStore:SetAsync(player.UserId.."-SandstoneCookie",shared.SandstoneCookie)
myDataStore:SetAsync(player.UserId.."-BurntCookie",shared.BurntCookie)
myDataStore:SetAsync(player.UserId.."-CactusCookie",shared.CactusCookie)
myDataStore:SetAsync(player.UserId.."-CFCookie",shared.CFCookie)
myDataStore:SetAsync(player.UserId.."-TinyCookie",shared.TinyCookie)
end)
if success then
print("Data saved!")
else
print("Data save error.")
warn(errormessage)
end
end)
My problem is when the player leaves the game. The TinyCookie and CactusCookie variables are not saved, and when I leave the game I get warned with "Argument 2 missing or nil" from the warn on line 127. Can I get some help?

2 comments
The .."-CookieType" is used so I can save multiple values to the UserID, the comma comes after that, with the variable that I want to change.
o I see