I want to know if the player’s data is empty or not. But I do not know how to check if the data is empty. I have tried looking on the DevForum but didn’t find anything and I did not find any tutorials on what I’m trying to achieve.
Here is my code :
players.PlayerAdded:Connect(function(player)
local agility = Instance.new("NumberValue", player.Character or player.CharacterAdded:Wait())
agility.Name = "Agility"
agility.Value = player.Character.Humanoid.WalkSpeed
local race = Instance.new("StringValue", player)
race.Name = "Race"
local playerUserId = "Player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = dataStore:GetAsync(playerUserId)
end)
if success then
race.Value = randomRace
end
end)
players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
Race = player.Race.Value,
}
local success, errormessage = pcall(function()
dataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data Saved!")
else
print("Error when saving Data!")
warn(errormessage)
end
end)
So right here I want to set a random race to the player, but only for the first time he joins. After that, I’m gonna set his value to the data.Race.
if success then
race.Value = randomRace
end
I am grateful to anyone that can help me!