Save Player Data with Roblox Datastores

preview_player
Показать описание


TIMESTAMPS ►
00:00 Intro
00:15 What is Datastore
01:27 Saving data
07:45 Loading data
12:26 Enabling API Services
14:00 Combining Leaderstats and Table data
15:43 Testing
16:16 Editing Datastores
16:58 Handling Server Shutdown
20:40 Outro
Рекомендации по теме
Комментарии
Автор

I was never good with how to use tables so this helped a ton, thank you.

Kaizentry
Автор

Can we all agree GnomeCode is the best roblox lua teacher on youtube!! 😊

huttle
Автор

Out of the many YouTubers that I've watched to learn Roblox scripting, you GnomeCode have taken 1st place. I appreciate you not skipping over or poorly explaining even the smallest of details that may be crucial for a beginner to understand. Thank you for the great video.

Martinchi
Автор

I hope you had a wonderful Christmas with your family. Nice to see you still pushing out videos.

GigaGnome
Автор

This was a great video to help make Datastores clear whilst waiting for Doors part 8. Also for Doors part 8 you should make the other place where everyone joins so you can go into a match with your friends and nobody else

bisoncool
Автор

great video as ever!
One small point. I would save the Player.UserId to a variable when saving or you wont be able to use it if the first attempt fails as the player object will be gone by then.

also, not too big a problem, but with normal datastores there is a limit of 1 read/write per 6 seconds to the same key

mr_griffolukegriffiths
Автор

GnomeCode is awesome. He makes actually good videos and explains almost everything. Keep it up GnomeCode!

keeguri
Автор

I was gonna bash on the gnome but this is pretty well-engineered. Wish i had you when i was learning how to code on Lua.

YuinAstrophel
Автор

Thanks gnome for always doing tutorials on things we all know other roblox how to creators can never do due to their laziness

Ironbaby
Автор

It didn't work and now it's 3am and I'm struggling on how the hell the leaderboard disappeared:, D

aznya
Автор

i was about to add datastores and then i got the notification about a gnomecode video

DaAccountName
Автор

i did have to get some help for more leaderstats but your a lifesaver i spent hours on trying before hand thanks

Yuzumo
Автор

All the other videos I've watched show you how to do it but don't teach you so thank you gnomecode

_toastedbagels
Автор

thank you gnomecode for making awesome tutorials and inspiring tons of great games!

waffle_doge
Автор

i made a datastore but one of the variables doesn't work, when it changes, it doesn't fire the "changed" function

Afarmcow
Автор

Amazing video, I learned so much like how tables work and ipairs!

PoggersFloppa
Автор

Best lua teacher!, A very calming voice too, Not a screechy 9 yr old, ty

scratchthat
Автор

The Script:

local Players = game:GetService("Players")
local RunService =
local DatastoreService =

local database =
local sessiondata = {}

local DefaultData = {

["Dollars"] = 50

}

local function PlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"

local Dollars = Instance.new("NumberValue", leaderstats)
Dollars.Name = "Dollars"


local sucsess = nil
local PlayerData = nil
local attempt = 1

repeat
sucsess, PlayerData = pcall(function()
return
end)

if not sucsess then
warn(PlayerData)
task.wait(3)
end

attempt += 1
until sucsess or attempt == 5

if sucsess then
print("Connected To Database")

if not PlayerData then
print("No User Data Found, Assigning Default Data")
PlayerData = DefaultData
end
sessiondata[player.UserId] = PlayerData

else
warn("Unable To Get Data For User: "..player.Name)
player:Kick("Unable To Load Your Data, Please Try Again Later! :D")
end

Dollars.Value = -- SYNC LEADERSTATS WITH DATASTORE

= Dollars.Value
end)
leaderstats.Parent = player


end

local function PlayerRemoved(player)
if sessiondata[player.UserId] then
local sucsess = nil
local errorMsg = nil
local attempt = 1

repeat
sucsess, errorMsg = pcall(function()
database:SetAsync(player.UserId, sessiondata[player.UserId])
end)

if not sucsess then
warn(errorMsg)
task.wait(3)
end

attempt += 1
until sucsess or attempt == 5

if sucsess then

print("Data Saved For User: "..player.Name)

else
warn("Data Unable To Save For User: "..player.Name)

end

end
end

local function ServerShutdown()

if RunService:IsStudio() then
return
end

print("Handling Server Shutdown")
for i, plr in ipairs(Players:GetPlayers()) do
task.spawn(function()
PlayerRemoved(plr)
end)
end
end




halalouis
Автор

working on a new game and stuff like thisll really help. thanks, gnome!

RichRBLX
Автор

Great Video! I learnt a lot from this channel

dunialajla