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
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
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I think you should save the value everytime the value changes. That way you have less of a chance of losing your data.