My game is based off leaderstats, and I need it to save AND be FilteringEnabled. I can't get the datastore to work, however. Here is the code:
-- Read the description of the model for details, it pretty much says to just put it in.
function onPlayerEntered(player)
wait(5)-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
end
end
end
end
function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

11 comments
WaitForDataReady()? Isnt that Data Persistence?
Yes it is. My question is, how to I get it to work with FilteringEnabled?
Step one, dont use data persistence, use datastore service
And all datastore manipulation need to be handled server sided. So any local scripts would invoke a remote function that returns relevant data it needs from the server.
So, how do I use DataStore? (Sorry I am noobish at scripting)
I still dont get how people find out about data persistence, if you managed to dig that far into the wiki you should already know not to use it.
There's an article on it in the wiki but ill throw this at you off of the top of my head, im on mobile...
Lol so am I. Thanks!
local dataStoreService = game:GetService("DataStoreService"); local pointsDataStore = dataStoreService:GetDataStore("Points"); pointsDataStore:SetAsync(plr.UserId, 1337); pointsDataStore:GetAsync(plr.UserId)
Read the wiki article though, theres more methods you can use and theres information about legal datatypes you can SetAsync and information on request limita
So, I have two questions. What does IserId, 1337 do, and how would I save all the values in leaderstats?