How would I do an if/then statement that would determine if the player has Data Saved or not?
For example:
local data = RankDS:GetAsync(Player.UserId.."-rank")
if data ~= nil then
Level.Value = 1
else
Level.Value = data
end
How would I do an if/then statement that would determine if the player has Data Saved or not?
For example:
local data = RankDS:GetAsync(Player.UserId.."-rank")
if data ~= nil then
Level.Value = 1
else
Level.Value = data
end
IDK if your syntax is correct or if it will work, but shouldn’t this:
if data ~= nil then
be:
if data == nil then
Your script would throw ‘data’ away if its not nil, and use it if its nil.
There is an example usage here:
https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/GetAsync
most relevant portion being:
local myGold
local success, err = pcall(function()
myGold = goldDataStore:GetAsync(playerKey) or STARTING_GOLD
end)
if success then
gold.Value = myGold
else
-- Failed to retrieve data
end
so, to convert your example to something similar maybe this:
local data
local success, err = pcall(function()
data = RankDS:GetAsync(Player.UserId.."-rank") or 1
end)
if success then
Level.Value = data
else
-- Failed to retrieve data
end