Lvl doesn't work

For some reason my lvl system does not work. There is no error. The problem is that when the exp is greater than the lvl it does not change.
Please help, and have a greadt day.

Script:

local Lvl = script.Parent.LeaderstatsScript:WaitForChild("Lvl")
local Exp = script.Parent.LeaderstatsScript:WaitForChild("Exp")

Exp.Changed:Connect(function()
	if Exp.Value >= Lvl.Value * 100 then
		Lvl.Value = Lvl.Value + 1
		Exp.Value = 0
	end
end)

Is the value being changed from the Server or the Client? If the client is changing the value, it won’t replicate to the server. What type of script is this and where is it parented?

local Lvl = script.Parent.LeaderstatsScript:WaitForChild("Lvl")
local Exp = script.Parent.LeaderstatsScript:WaitForChild("Exp")
local IsChanging = false -- boolean variable to show whether or not the script is editing the value

Exp:GetPropertyChangedSignal("Value"):Connect(function()
   if (Exp.Value >= Lvl.Value * 100) and not IsChanging then
      -- checks the exp requirement and the boolean property
      IsChanging = true -- changes the property so any future events won't fire and run this scope until the variable is 'false' again
         Lvl.Value += 1
         Exp.Value = 0
      IsChanging = false -- resets the variable
   end
end)

I also advise using a debounce (as seen in the script above) because changing a property whilst inside the Instance’s Changed event, can cause an infinite loop.

Would it matter that it is a local script that is parented to server script service?

Yes, ServerScriptService is for server scripts only, localscripts won’t run there.

image

So, where should I place it________________?

Judging by your script, I’d say StarterPlayerScripts.

local Player = game.Players.LocalPlayer -- get the local player
local Lvl = Player:WaitForChild("LeaderstatsScript"):WaitForChild("Lvl")
local Exp = Player.LeaderstatsScript:WaitForChild("Exp")
local IsChanging = false

Exp:GetPropertyChangedSignal("Value"):Connect(function()
   if (Exp.Value >= Lvl.Value * 100) and not IsChanging then
      IsChanging = true
         Lvl.Value += 1
         Exp.Value = 0
      IsChanging = false
   end
end)

It says infinite yield_____________________.

Infinite yield for? If it’s for LeaderstatsScript that means there’s nothing named LeaderstatsScript as a child of the player. If it’s for any of the other values, that means that there’s nothing named Lvl or Exp inside LeaderstatsScript.

Infinite yield possible on 'Players.SilentSuprion:WaitForChild(“LeaderstatsScript”)

LocalScripts actually replicate to PlayerScripts, so, the code should be:

local Lvl = Player.PlayerScripts:WaitForChild("LeaderstatsScript"):WaitForChild("Lvl")

I’d recommend doing this on the server since your trying to edit a leaderstat value.

local Players = game:GetService('Players')

Players.PlayerAdded:Connect(function(player)
local leaderStats = player:WaitForChild('leaderstats')

local lvl = leaderStats:WaitForChild('Lvl')
local exp = leaderStats:WaitForChild('Exp')

exp:GetPropertyChangedSignal('Value'):Connect(function()
if exp.Value >= lvl.Value * 100 then
lvl.Value += 1
exp.Value = 0
end
end)
end)
1 Like

It works great, thanks for your help but it does not change the Exp value to 0.

Made a typo, I’ll edit that.

char limit

I know I gave you solution but it still doesn’t change the exp value to 0.

Any errors? Also make sure that the script is a serverscript and is inside ServerScriptService.

I tried putting it in server script service but because it is a local script it does not work and there is no error.

Put the script inside a serverscript (default script) and parent it to ServerScriptService.

Wouldn’t that change everyone’s level?

I’m pretty sure it doesn’t since it just listens for when the value is changed.

Oh I’m sorry it actually works but it doesn’t change the text but I can do that.