Hello, I don't know why this script isn't working can someone please help. Someone told me to add BindToClose but I'm not sure where to add it.
Can someone please tell me what's wrong with the script or where to add the BindToClose. No errors show in the console.
Script:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local jumps = Instance.new("IntValue")
jumps.Name = "Jumps"
jumps.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-jumps")
end)
if success then
jumps.Value = data
else
warn(errormessage)
print("There was an error whilst getting your data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-jumps", player.leaderstats.Jumps.Value)
end)
if success then
print ("Data Saved Successfully")
else
print("There was an error when saving")
warn(errormessage)
end
end)

2 comments
Use BindToClose is a DataModel's function.
game:BindToClose(function)Use BindToClose is a DataModel's function.
game:BindToClose(function)