Text label problem

Basically, the text instead of showing the actual requirement, it just begins going into the negatives and acting all weird.
I’m confused and not sure why this is happening
Text label script:

local player = game.Players.LocalPlayer
script.Parent.Text = "Exp required to level up: "..  player:WaitForChild("Levels"):WaitForChild("Requirement").Value - player:WaitForChild("Requirement"):WaitForChild("Exp").Value
player.Requirement.Exp.Changed:Connect(function()
	script.Parent.Text = "Exp required to level up: ".. player:WaitForChild("Levels"):WaitForChild("Requirement").Value - player:WaitForChild("Requirement"):WaitForChild("Exp").Value
end)

Server script:

game.Players.PlayerAdded:Connect(function(plr)
	local Requirement = plr:WaitForChild("Levels"):WaitForChild("Requirement").Value
	local level = plr:WaitForChild("Levels"):WaitForChild("Level")
	local exp = plr:WaitForChild("Requirement"):WaitForChild("Exp")
	Requirement = level.Value * 25
	if exp.Value >= Requirement then
		Requirement = level.Value * 25
		exp.Value = 0
		level.Value +=1
	end
	exp.Changed:Connect(function()
	if exp.Value >= Requirement then
			Requirement = level.Value * 25
		exp.Value = 0
		level.Value +=1
	end
	end)
end)

Server script works fine, though I think it’d be better to show you that as well

Can anybody assist me with this?

Use “math.abs()”, this turns minus to plus numbers.
Also, “WaitForChild()” should be used not more than once in a sentence. In some cases not more than one line

So your TextLabel script should be:

local player = game.Players.LocalPlayer

local levels = player:WaitForChild(“Levels”)
local requirement = player.Requirement

local gap = math.abs( levels.Requirement.Value - requirement.Exp.Value)

script.Parent.Text = "Exp required to level up: "…gap

player.Requirement.Exp.Changed:Connect(function()

gap = math.abs( levels.Requirement.Value - requirement.Exp.Value)

script.Parent.Text = "Exp required to level up: "…gap

end)

1 Like

But now instead, the exp required just begins going up instead of going down when I get exp.
Also I don’t think it solves the problem, it still won’t give an accurate value.

I see the issue now lol,
“required exp” is to be subtracted from “player exp” to make sense

Just swap these two places
And if you’re getting “4.772” type numbers, then use math.ceil() on the “gap”

Still experiencing the same problem.
Did I implement it correctly:

	local player = game.Players.LocalPlayer

local levels = player:WaitForChild("Levels")
local requirement = player.Requirement

local gap = math.ceil(math.abs( requirement.Exp.Value - levels.Requirement.Value))

script.Parent.Text = "Exp required to level up: ".. gap

player.Requirement.Exp.Changed:Connect(function()

gap = math.ceil(math.abs( requirement.Exp.Value - levels.Requirement.Value))

	script.Parent.Text = "Exp required to level up: ".. gap

end)

Your Server script has a slight flaw.
You’re setting “Requirement” value before increasing “Level” value

Put “level.Value += 1” lines above “Requirement = level.Value * 25”

Thank you for pointing out that flaw, could have caused a whole other host of problems.
But the same problem occurs :slightly_frowning_face: