|
I've never attempted to learn data stores, as I figured I would never create a successful game in need of data store. I'm just visiting the forum to see what other scripters have to say about data store before I go to the wiki, thanks. |
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
People will tell you to pcall to avoid errors, and they will make it much harder than it needs to be.
It's real simple. Here's how I do it for my games:
sessionData = {}
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
end) -- end of character added
-- let's get the data
local success,data = pcall(function()
PlayerDataStores:GetAsync(player.UserId)
end)
if not success then
print("Roblox had an error loading data")
player:Kick("ROBLOX could not load your save file! Please try again soon.")
-- ideally this part would retry a few times, but I don't have the patience for that.
else
if not data then -- if they are a first-timer
print("no data found for ",player.Name)
sessionData[player.UserId] = defaultData -- give them a blank template
PlayerDataStores:SetAsync((player.UserId),sessionData[player.UserId])
else
print("data successfully found for ",player.Name)
sessionData[player.UserId] = data
end
end
player:LoadCharacter()
end) |
|
|
|
Hold on real quick. I think I'm learning something here now.
local success,data = pcall(function()
PlayerDataStores:GetAsync(player.UserId)
end)
So here you call two functions (pcall and getasync), how do you know which order the values are returned in?
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
Pcall will return the success (true or false), and the message (if there is an error message), and then subsequently anything returned by the function within
If success, it will omit returning the error message from what I can tell and just go straight into the returns of the function within.
|
|
|
data stores are easy
define data store service
add value to data store service
read data store
save value with a button or when player leaves the game
|
|
|
Thanks to all who contributed to this post. |
|
|
or logical operator, i learned that if something doesnt return to true, or operators can check if the next works
instead of using p call use or
print(hi) or print(false) |
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
No Data doesn't mean Error
so that wouldn't really work |
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
It's stylized as ROBLOX, type it however you want.. |
|
LaeMVPJoin Date: 2013-06-24 Post Count: 4416 |
if you is really weeby you could do like local data while (pcall(function() data = ################ end)) do wait(1) end |
|
|
Read the link I sent to you @Soy
And yes, I’m really toxic |
|
diaworld2Join Date: 2014-05-11 Post Count: 326 |
is pcall playercall? |
|
|