So like I need to check if anything related to getting the data worked, but if the result is nil I want to use it to code further.
-- Variables
local xpRemote = game.ReplicatedStorage:WaitForChild("XPsystem remote")
local globalCooldown = 60
local dataBaseService = game:GetService("DataStoreService")
local XPdataBase = dataBaseService:GetDataStore("globally_XP")
local Players = game:GetService("Players")
local rewardningXP = nil
local XPRewardPerRank = {
["Ranks"] = {
[2] = 15;
[3] = 25;
[4] = 35;
[5] = 50;
[6] = 60;
[7] = 70;
[8] = 80;
[10] = 80;
[11] = 90;
[12] = 100;
[13] = 120;
[251] = 130;
[252] = 140;
[253] = 150;
[254] = 150;
[255] = 150
}
}
local maxRequiredToRankUp = {
[2] = 3000;
[3] = 6000;
[4] = 12000;
[5] = 24000;
[6] = 35000;
[7] = 50000;
[8] = 100000;
}
-- Functions
function updateXPData(player)
local rankIDingroup = player:GetRankInGroup(32532119)
local XP = nil
local maxReq = nil
player.PlayerGui:WaitForChild("Xp").Main.Xppermin.Text = "XP-PM: " ..XPRewardPerRank["Ranks"][rankIDingroup]
XP = XPdataBase:GetAsync(player.UserId .. "_XPDataStore")["XP"]
if XP == nil then
player:Kick("Something went wrong getting your XP, please contact our staff team!")
end
if maxRequiredToRankUp[rankIDingroup] == nil then
player.PlayerGui.Xp.Main.Xphave.Text = XP .. " / MAX XP"
player.PlayerGui.Xp.Main.Xpbarbackground.Have.Size = UDim2.new(1,0,1,0)
player.PlayerGui.Xp.Main.percent = "100%"
else
player.PlayerGui.Xp.Main.Xphave.Text = XP .. " / " .. maxRequiredToRankUp[rankIDingroup] .. " XP"
local mathy = (XP / maxRequiredToRankUp[rankIDingroup] * 100)
player.PlayerGui.Xp.Main.percent.Text = math.ceil(mathy).. "%"
end
end
-- Event Listeners
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
updateXPData(player)
end)
end)
I basically need to check if someone already has a value in their XP or not. But I also want to use pcall to not break the entire code when something went wrong?