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?
game.Players.PlayerRemoving:connect(function(p) -- you need to connect the listener to a function --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))
MINOR MISTAKE ONLY THIS WONT BE A LENGTHY ANSWER
or will it????
You cannot call PlayerRemoving like a function, but you can use :connect on it, which you aren't.