I'm trying to do a DataStorage code and the PlayerRemoving function just doesnt work. Output: 18:05:49.960 - Workspace.leaderstatsSave:36: attempt to call field 'PlayerRemoving' (a userdata value)
Code:
game.Players.PlayerRemoving(function(p)
--SAVE--
local DataStore = game:GetService("DataStoreService"):GetDataStore(p.userId)
local stats = p.leaderstats:GetChildren()
local s1 = {}
for i=1,#stats do
local n = stats[i].Name
s1[n] = stats[i].Value
end
DataStore:SetAsync("stats",s1)
--print("Saved "..p.Name)
end)
Help?

1 comment
Thanks for reminding me, I completely forgot to add :connect in front of function.