Hi Scripters of Roblox, how can I make it so that when a user joins a game, it checks for a Value in a data store, if it has a value then thats the value of the users leaderstat, but if there isnt any data in the data store, then the leaderstat = 0
If you want to get data, you need to use :GetAsync(). You can learn more about data stores here.
Yeah, im saying is it Money.Value = MoneyStore:GetAsync(player.Id) or 0?
Because cant the value be nil if it hasnt been set
With this code, the value will be 0 if there is no data.
Money.Value = MoneyStore:GetAsync(player.UserId) or 0
local function OnPlayerAdded(Plr) local UserD; local Success, Error = pcall(function() UserD = DS:GetAsync(queryplr.UserId);end); if Error then warn("Failed to load "..queryplr.Name.." Data") return; end; --< You can make repetitive calls if you want, I normally don't :/ if(not UserD)then UserD=CreateNewData(); end; end;
Always try to wrap external calls in a pcall
Huh. That is so advanced lmaooo. Ik what pcall is but
Here you can check my tutorial if you want!
It has all sort of stuff you can learn for datastores.
Btw if the player doesn’t have any data the automatic will be set to 0.
That will wipe their data if there’s an error retrieving it. I don’t think that’s what pcall should be used for.
Thank you for that, maybe I should stop using the devforum at 2 AM. I’ll edit my post also