How to save a player data in studio lite

  Рет қаралды 272

BaconScripting

BaconScripting

Күн бұрын

Hi guys today I will show you how to save a player data so
Pls consider to like and subscribe it help a lot so pls like and sub
------------The Script----------
-Put this script in Workspace--
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- Create or get the DataStore
local playerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
-- Function to create leaderstats
local function createLeaderstats(player)
-- Create a Folder for leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create a new IntValue for YourStatsName
local yourStatsName = Instance.new("IntValue")
yourStatsName.Name = "YourStatsName"
yourStatsName.Value = 0 -- default value
yourStatsName.Parent = leaderstats
-- Create another IntValue for AnotherStatsName
local anotherStatsName = Instance.new("IntValue")
anotherStatsName.Name = "AnotherStatsName"
anotherStatsName.Value = 0 -- default value
anotherStatsName.Parent = leaderstats
end
-- Function to load player data
local function loadPlayerData(player)
local success, data = pcall(function()
return playerDataStore:GetAsync(player.UserId)
end)
if success and data then
player.leaderstats.YourStatsName.Value = data.YourStatsName -- Load YourStatsName
player.leaderstats.AnotherStatsName.Value = data.AnotherStatsName -- Load AnotherStatsName
else
warn("Could not load data for player: " .. player.Name)
end
end
-- Function to save player data
local function savePlayerData(player)
local data = {
YourStatsName = player.leaderstats.YourStatsName.Value, -- Save YourStatsName
AnotherStatsName = player.leaderstats.AnotherStatsName.Value -- Save AnotherStatsName
}
local success, errorMessage = pcall(function()
playerDataStore:SetAsync(player.UserId, data)
end)
if not success then
warn("Could not save data for player: " .. player.Name .. " - " .. errorMessage)
end
end
-- Connect functions to player events
Players.PlayerAdded:Connect(function(player)
createLeaderstats(player)
loadPlayerData(player)
-- Save data when the player leaves
player.AncestryChanged:Connect(function(_, parent)
if parent == nil then
savePlayerData(player)
end
end)
end)
-- Save data when the game is closed or the server shuts down
game:BindToClose(function()
for _, player in ipairs(Players:GetPlayers()) do
savePlayerData(player)
end
end)

Пікірлер: 9
@BaconBoyScripting
@BaconBoyScripting 2 ай бұрын
Script in Description
@RealBaconLite
@RealBaconLite 2 ай бұрын
U NEED 10 K SUBS
@BaconBoyScripting
@BaconBoyScripting 2 ай бұрын
Thanks you
@RealBaconLite
@RealBaconLite 2 ай бұрын
U welcome
@Diegardox3000
@Diegardox3000 Ай бұрын
Fr
@Diegardox3000
@Diegardox3000 Ай бұрын
he is goated
@BaconBoyScripting
@BaconBoyScripting Ай бұрын
Ty​@@Diegardox3000
@Theexploiterguy-r1x
@Theexploiterguy-r1x Ай бұрын
Does save players tool when die or join the game?
Datastore: A Scripter's Worst Nightmare Explained
9:55
Ludius
Рет қаралды 24 М.
I Recreated Arcane With $0
15:01
Noggi
Рет қаралды 1,5 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
I made a Scratch game
6:11
Rowan Builds
Рет қаралды 84
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 909 М.
I Scraped the Entire Steam Catalog, Here’s the Data
11:29
Newbie Indie Game Dev
Рет қаралды 711 М.
How to make Over-Head GUI In Studio Lite
3:48
BaconScripting
Рет қаралды 48
Roblox DataStores Are Actually Extremely Simple..
13:38
Paul1Rb
Рет қаралды 4,5 М.
THE AMAZING DIGITAL CIRCUS - Ep 4: Fast Food Masquerade
23:20
GLITCH
Рет қаралды 53 МЛН
Reading YOUR Discord Mod Applications 2
13:25
SoundDrout
Рет қаралды 2,3 МЛН
Somebody emailed me a trojan virus
14:06
Bog
Рет қаралды 1,3 МЛН
I made a Roblox Simulator Using ONLY my PHONE
8:15
CodeBro29
Рет қаралды 600 М.
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН