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

Is it possible to get this script to save on a 1 player server?

https://www.youtube.com/watch?v=D3SS1Wrxbl4&feature=youtu.be

U MUST WATCH

local ds = game:GetService("DataStoreService")

local coinsODS = ds:GetOrderedDataStore("officialpointfortlolSaveSystem")


local timeUntilReset = 100


while wait(1) do
	
	
	timeUntilReset = timeUntilReset - 1
	
	script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
	
	
	if timeUntilReset == 0 then
		
		timeUntilReset = 100
	
	
		for i, plr in pairs(game.Players:GetPlayers()) do
			
			coinsODS:SetAsync(plr.UserId, plr.leaderstats.Changes.Value)
		end
		
		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
			
			if leaderboardRank.ClassName == "Frame" then
				leaderboardRank:Destroy()
			end
		end
		
		
		local success, errorMsg = pcall(function()
			
			local data = coinsODS:GetSortedAsync(false, 50)
			local coinsPage = data:GetCurrentPage()
			
			for rankInLB, dataStored in ipairs(coinsPage) do
				
				
				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local coins = dataStored.value
				
				
				local template = script.Template:Clone()
				
				template.Name = name .. "Leaderboard"
				
				template.PlrName.Text = name
				
				template.Rank.Text = "#" .. rankInLB
				
				template.Coins.Text = coins
				
				template.Parent = script.Parent				
			end			
		end)
	end
end

Ok, so what I am trying to do is save the global leaderboard, because if i leave on the 1 player server after the leaderboard loads in, then it does not save, and I wonder if this leaderboard happens through all servers too.

Someone said something about :BindToClose() but they didnt say where or how to really use it.

3 comments

0

If all players leave the game then you can use :BindToClose() to save all of their data before the server closes.

0

You can search for things (including BindToClose) at: https://developer.roblox.com/ ex, if you search BindToClose, the first result is DataModel:BindToClose(), which is the correct one, and even comes with examples: https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose

0

What is the problem at-hand??

1 answer

You can use :BindToClose() :)

4 comments

0

Huh?

0

yeah dude what

0

this does not give me anything

0

I mean I gave you something to work with just google it... It keeps the server open for another 30 seconds or so and allows you to run a function to save the players data. The issue that you were having is that the server for one player was closing as soon as they leave so no time to save

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