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.
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)
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.
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)