Value isn't updating

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

tonumber(---)
1 Like
  1. Is this a server or local script.

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.

Removed both, doesn’t work still. Thanks for the response though!

Try this

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.

This doesn’t work either. The rank in the GUI is the same as it was and doesn’t update when it should be updating:

There are also no errors in my output?

If not you will have to go back to the script which stuffs the correct value into here on recouvery of data…

Or, is it: player.RankInfo.XP.Value.value

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.

player.RankInfo.XP.Value.Value – is the integer value of the ItValue

You just missed it by one…

This is what happens when I add an extra Value after the original (player.RankInfo.XP.Value.Value):

Screen Shot 2021-10-07 at 7.21.40 PM

Did you check to see if the value is getting populated when you join? Look in the game explorer or else add some print statements to your script.

What does it print with:
print(player.RankInfo.XP.Value)

1 Like

It doesn’t seem like the value is changing or getting populated when I join. It stays at 10, like I made it to do so it doesn’t affect the script.

What Type is
player.RankInfo.XP.Value .-- illllllll

Yeah well, will your script print out that 10? That should still get you the first ranking into your GUI.

I think your problem is here:

local DisplayRank = player:WaitForChild("PlayerGui"):WaitForChild("Ranks").Frame.RankHere.Text

remove the .Text part, then set the value with DisplayRank.Text = “Noob” (or whatever you want to call them)

1 Like

That Error Message is from line 13 …

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.

1 Like