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

How do I put a data persistence in a value of a player?

In a player on my game, there's a value called Rank(string value) in game.Players.PlayerName

How do I make it so the string is saved and will appear as the same string next time they join a server

1 answer

You can use the DataStoreService.

Updated to save when the value is changed.

local DataStore = Game:GetService("DataStoreService"):GetDataStore("Rank")

local Requests = 0
local Max  = 60

function Good()
	return Requests <= Max
end

function UpdateMax()
	Max = 60 + 10 * #Game.Players:GetPlayers()
end


Game.Players.PlayerAdded:connect(function(Player)
	local Stat = Player:WaitForChild("leaderstats"):WaitForChild("Rank")
	Stat.Value = DataStore:GetAsync(Player.userId)
	Stat.Changed:connect(function()
		if Good() then
			DataStore:SetAsync(Player.userId,Stat.Value)
			Requests = Requests + 1
		end
	end)
end)
Game.Players.PlayerRemoving:connect(function()
	UpdateMax()
end)

Spawn(function()
	while wait(60) do
		Requests = 0
	end
end)

1 comment

0

I think you should save the value everytime the value changes. That way you have less of a chance of losing your data.

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