I know this issue is pretty basic but I haven’t gotten to work correctly for a while now. The issue seems to be with the playerremoving function. When the player leaves, it prints “player left” but not “player gone” or “player gone2”. So for some reason, the functions aren’t running properly and aren’t reaching the end. Anyone got a clue or see something I don’t?
local DataStoreService = game:GetService("DataStoreService")
local cashSave = DataStoreService:GetDataStore("CashStorage")
local daySave = DataStoreService:GetDataStore("DayStorage")
local day = game.Players.PlayerAdded
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local day = Instance.new("IntValue")
day.Name = "Day"
day.Value = "0"
day.Parent = leaderstats
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = "0"
cash.Parent = leaderstats
--Ingredient stats
local ingredients = Instance.new("Folder")
ingredients.Name = "Ingredients"
ingredients.Parent = player
local pineapple = Instance.new("BoolValue")
pineapple.Name = "Pineapple"
pineapple.Parent = ingredients
local olive = Instance.new("BoolValue")
olive.Name = "Olive"
olive.Parent = ingredients
local mushroom = Instance.new("BoolValue")
mushroom.Name = "Mushroom"
mushroom.Parent = ingredients
local spinach = Instance.new("BoolValue")
spinach.Name = "Spinach"
spinach.Parent = ingredients
local bananapepper = Instance.new("BoolValue")
bananapepper.Name = "Banana Pepper"
bananapepper.Parent = ingredients
local ham = Instance.new("BoolValue")
ham.Name = "Ham"
ham.Parent = ingredients
local chicken = Instance.new("BoolValue")
chicken.Name = "Chicken"
chicken.Parent = ingredients
local bacon = Instance.new("BoolValue")
bacon.Name = "Bacon"
bacon.Parent = ingredients
--cash load when join
local data
local success, errormessage = pcall(function()
data = cashSave:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("Error getting Cash Data")
warn(errormessage)
end
--day load when join
local data2
local success, errormessage = pcall(function()
data2 = daySave:GetAsync(player.UserId.."-day")
end)
if success then
day.Value = data2
else
print("Error getting Day Data")
warn(errormessage)
end
print("Joined Finished")
end)
game.Players.PlayerRemoving:Connect(function(player)
print("player left")
--cash save when leave
local success, errormessage = pcall(function()
cashSave:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
end)
if success then
print("Cash Data saved")
else
print("Cash Data not saved")
warn(errormessage)
end
print("player gone")
--day save when leave
local success, errormessage = pcall(function()
daySave:SetAsync(player.UserId.."-day",player.leaderstats.Day.Value)
end)
if success then
print("Day Data Saved")
else
print("Day Data not saved")
warn(errormessage)
end
print("player gone2")
end)