There are multiple methods for this:
** 1. Use a table **
You can use a table to store values for each player using this script:
local Players = {}
local Data = {}
function Remove(plrName)
for i, data in pairs(Players) do
if data == plrName then
table.remove(Players,i)
table.remove(Data,i)
return
end
end
end
function Add(plrName)
table.insert(Players,plrName)
table.insert(Data,"empty")
end
function Get(plrName)
for i, data in pairs(Players) do
if data == plrName then
return Data[i]
end
end
end
function Change(plrName,Change)
for i, data in pairs(Players) do
if data == plrName then
Data[i] = Change
return
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
Add(plr.Name)
end
game.Players.PlayerRemoving:Connect(function(plr)
Remove(plr.Name)
end
local PlayerData = Get(plr.Name)
print(tostring(PlayerData)
Change(plrName, "Your data here")
** 2. Use folders **
You can use folders inside players called "Leaderstats"
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
This method is using those leaderboards you see on top of players.
** 3. Use invisible folders **
Don't want that data being shown to other players via leaderboard? Change this line:
leaderstats.Name = "leaderstats"
to
leaderstats.Name = "stats"
Change the name to whatever you like! It's your choice!
I hope this helps!
Best,
TheLastHabanero
1 comment
https://developer.roblox.com/api-reference/function/Players/GetPlayers