I’m trying to make an internal rank system and if the XP in the player’s folder → value is more than the XP required to be that rank, it updates (when they rejoin the game).
I don’t know what is wrong but the value isn’t updating in my GUI (the rank is displayed on the GUI), and I’m not getting any errors.
Does anybody know what I did wrong?
Code
local ValueToGetCadet = 10
local ValueToGetOfficer = 50
local ValueToGetDetective = 200
local ValueToGetCorporal = 400
local ValueToGetSergeant = 750
local ValueToGetLieutenant = 1000
local ValueToGetCaptain = 2000
local ValueToGetDeputy = 4000
local ValueToGetChief = 10000
game.Players.PlayerAdded:Connect(function(player)
local XP = player:WaitForChild("RankInfo"):WaitForChild("XP").Value
local DisplayRank = player:WaitForChild("PlayerGui"):WaitForChild("Ranks").Frame.RankHere.Text
local function checkValues()
if XP >= ValueToGetCadet and XP < ValueToGetOfficer then
DisplayRank = "Cadet"
elseif XP >= ValueToGetOfficer and XP < ValueToGetDetective then
DisplayRank = "Officer"
end
end
checkValues()
print("Updated!")
while wait(10) do
checkValues()
end
end)
Video with the error:
Ignore the amount of variables there are, I decided to do that for now.
local ValueToGetCadet = "10"
local ValueToGetOfficer = "50"
local ValueToGetDetective = "200"
local ValueToGetCorporal = "400"
local ValueToGetSergeant = "750"
local ValueToGetLieutenant = "1000"
local ValueToGetCaptain = "2000"
local ValueToGetDeputy = "4000"
local ValueToGetChief = "10000"
You can try removing the quotation marks. If that doesn’t work you can also remove the
If it’s a server script then use this script, this should fix it.
local ValueToGetCadet = "10"
local ValueToGetOfficer = "50"
local ValueToGetDetective = "200"
local ValueToGetCorporal = "400"
local ValueToGetSergeant = "750"
local ValueToGetLieutenant = "1000"
local ValueToGetCaptain = "2000"
local ValueToGetDeputy = "4000"
local ValueToGetChief = "10000"
local value1 = tonumber(ValueToGetCadet)
local value2 = tonumber(ValueToGetOfficer)
local value3 = tonumber(ValueToGetDetective)
local value4 = tonumber(ValueToGetCorporal)
local value5 = tonumber(ValueToGetSergeant)
local value6 = tonumber(ValueToGetLieutenant)
local value7 = tonumber(ValueToGetCaptain)
local value8 = tonumber(ValueToGetDeputy)
local value9 = tonumber(ValueToGetChief)
game.Players.PlayerAdded:Connect(function(player)
local XP = player:WaitForChild("RankInfo"):WaitForChild("XP")
local DisplayRank = player:WaitForChild("RankInfo"):WaitForChild("RankValue")-- change this to a string value and update it through a localscript (via the gui)
local function checkValues(x)
if x == value1 then
DisplayRank.Value = "Cadet"
elseif x == value2 then
DisplayRank.Value = "Officer"
elseif x == value3 then
DisplayRank.Value = "thigny"
end
end
checkValues()
end)
The value isn’t updating because you aren’t getting the updated value of XP. You shouldn’t get the value of XP in the declaration because it’s constant. You should get the value of XP in the if statements.
game.Players.PlayerAdded:Connect(function(player)
local XP = player.RankInfo.XP
local DisplayRank = player.PlayerGui:WaitForChild("Ranks").Frame.RankHere
if XP.Value >= value1 and XP.Value < value2 then
DisplayRank.Text = "Cadet"
print("Value Updated!")
elseif XP.Value >= value2 and XP.Value < value3 then
DisplayRank.Text = "Officer"
print("Value Updated!")
end
end)
I am trying to get the value of XP right when the player joins (as I have datastore, the data is saved and when I rejoin, the data should be where it was where I left). I just want to make sure this script works when I join the game. The value isn’t updating when I join.
I don’t know if there is a difference when writing value and Value.
XP is the value that is stored inside the Player (inside a folder) and there is a datastore for it meaning that if and when I join the game, the value should be 10 because thats the value I had when I left the game before. I believe it would be player.RankInfo.XP.Value.
Yeah, so its getting the value fine, read the post I made regarding DisplayRank, you assigned it to the text value and I think you meant to assign it to the textlabel object.