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

0

WaitForDataReady()? Isnt that Data Persistence?

0

Yes it is. My question is, how to I get it to work with FilteringEnabled?

0

Step one, dont use data persistence, use datastore service

0

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.

0

So, how do I use DataStore? (Sorry I am noobish at scripting)

0

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.

0

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...

1

Lol so am I. Thanks!

0

local dataStoreService = game:GetService("DataStoreService"); local pointsDataStore = dataStoreService:GetDataStore("Points"); pointsDataStore:SetAsync(plr.UserId, 1337); pointsDataStore:GetAsync(plr.UserId)

0

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

0

So, I have two questions. What does IserId, 1337 do, and how would I save all the values in leaderstats?