Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my datastore is still not working with filtering enabled. can any of you guys help me out here?

I also wanted to let you that that FE is on and the script is in the workspace

local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")

game:GetService("Players").PlayerAdded:connect(function(plr)
	local leader = Instance.new("Folder",plr)
	leader.Name = "leaderstats"
	
	local Credits = Instance.new("IntValue",leader)
	Credits.Name = "Credits"
	
	local Diamonds = Instance.new("IntValue",leader)
	Diamonds.Name = "Diamonds"
	
    local savedData = DSService:GetAsync(plr.UserId.."-Currency")
 	
	if savedData then
      Credits.Value = savedData[1]
 	  Diamonds.Value = savedData[2]
	else
	  local values = {Credits.Value, Diamonds.Value}
	  DSService:SetAsync(plr.UserId.."-Currency",values)
	end
end)

game:GetService("Players").PlayerRemoving:connect(function(plr)
	local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
	DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave)
end)

while wait(300) do
	for i,v in pairs(game:GetService("Players"):GetChildren()) do
		DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value)
	end
end

3 comments

0

What’s the issue? I don’t have a computer to find errors at the moment.

0

How are you changing the values?

0

I already tested your script , it works fine... workspace > Script ( Above content ) Press F9 > Server log then game.Players.NAMEHERE.leaderstats.Diamonds.Value = 9999.

1 answer

The server is shutting down before the data saves. To prevent this, you need to add game:BindToClose() to the script. Try this instead

local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")
local Saving = 0

game:BindToClose(function()
	repeat wait() until Saving <= 0
end)

game:GetService("Players").PlayerAdded:connect(function(plr)
	local leader = Instance.new("Folder",plr)
	leader.Name = "leaderstats"

		local Credits = Instance.new("IntValue",leader)
		Credits.Name = "Credits"
	
		local Diamonds = Instance.new("IntValue",leader)
		Diamonds.Name = "Diamonds"

	local savedData = DSService:GetAsync(plr.UserId.."-Currency")

	if savedData then
		Credits.Value = savedData[1]
		Diamonds.Value = savedData[2]
	else
		local values = {Credits.Value, Diamonds.Value}
		DSService:SetAsync(plr.UserId.."-Currency",values)
	end
end)

game:GetService("Players").PlayerRemoving:connect(function(plr)
	Saving = Saving + 1
	local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
	DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave)
	Saving = Saving - 1
end)

while wait(300) do
	for i,v in pairs(game:GetService("Players"):GetChildren()) do
		DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value)
	end
end

3 comments

0

thanks

0

it still only work's in studio

0

even though the leaderboard shows that the value changed in roblox

This discussion is preserved as it was. New answers, comments, and votes are closed.