Level System Worked Perfectly Fine and Stopped Working All of a Sudden

My level system has always worked until I made a few tweaks on it. Can someone tell me what the problem is?

Player.leaderstats.Exp:GetPropertyChangedSignal(“Value”):Connect(function()
local RequiredExp = Player.leaderstats.Level.Value * 100 + 100

	if Player.leaderstats.Exp.Value == RequiredExp or Player.leaderstats.Exp.Value >= RequiredExp then
		Player.leaderstats.Exp.Value -= RequiredExp
		Player.leaderstats.Level.Value += 1
	end
end)
2 Likes

Have you tried adding random prints and comments?

2 Likes

Yes, and I’ve tried figuring out what the problem is but I simply can’t. I’m an amateur scripter so I have no idea what I did wrong. Probably some stupid little mistake.

1 Like

Your code looks perfectly fine to me. If it randomly broke and the code looks fine it could be Roblox’s thing, hence the suggestion to add prints and comments. My only other idea is maybe a race condition? Wait for the value to exist before using it and see if that fixes it.

1 Like

I just tried putting some print statements in a couple places and none of them ran. It seems like there’s something wrong with the “GetPropertyChangedSignal”. Apparently a lot of people are having an issue with it so maybe that’s the problem.

1 Like

Try adding these lines of code to the top:

Player:WaitForChild("leaderstats")
Player.leaderstats:WaitForChild("Exp")

If that doesn’t work try connecting to .Changed instead with an if.

1 Like

The two lines wouldn’t do anything since it’s in the same script as the function that creates the value:

local Level = Instance.new(“IntValue”)
Level.Name = “Level”
Level.Parent = leaderstats

local Exp = Instance.new("IntValue")
Exp.Name = "Exp" 
Exp.Parent = leaderstats

So i’ll just try connect to .Changed.

1 Like

Can you show the rest of the script, like where is Player being defined?

1 Like

The script is really long but the Player is being defined in a PlayerAdded function.

–leaderstats–

game.Players.PlayerAdded:connect(function(Player)
local leaderstats = Instance.new(“IntValue”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player

local Level = Instance.new("IntValue") 
Level.Name = "Level" 
Level.Parent = leaderstats

local Exp = Instance.new("IntValue")
Exp.Name = "Exp" 
Exp.Parent = leaderstats

local Coins = Instance.new("IntValue")
Coins.Name = "Coins" 
Coins.Parent = leaderstats

local Gems = Instance.new("IntValue")
Gems.Name = "Gems" 
Gems.Parent = leaderstats

--Other--

local Rank = Instance.new("StringValue")
Rank.Name = "Rank"
Rank.Parent = Player

--Quests--

local QuestStats = Instance.new("Folder")
QuestStats.Name = "QuestStats"
QuestStats.Parent = Player

local QuestNum = Instance.new("IntValue")
QuestNum.Name = "QuestNum"
QuestNum.Value = 1
QuestNum.Parent = Player

local QuestInProgress = Instance.new("BoolValue")
QuestInProgress.Name = "QuestInProgress"
QuestInProgress.Value = false
QuestInProgress.Parent = Player

--Quest Stats--

local TimePlayed = Instance.new("IntValue")
TimePlayed.Name = "TimePlayed"
TimePlayed.Value = 0
TimePlayed.Parent = QuestStats

--Codes--

local Codes = Instance.new("Folder")
Codes.Name = "Codes"
Codes.Parent = Player

local Code1 = Instance.new("BoolValue")
Code1.Name = "Code1"
Code1.Value = false
Code1.Parent = Codes

local Reward1 = Instance.new("StringValue")
Reward1.Name = "Reward"
Reward1.Value = "Coins25"
Reward1.Parent = Code1

local Code2 = Instance.new("BoolValue")
Code2.Name = "Code2"
Code2.Value = false
Code2.Parent = Codes

local Reward2 = Instance.new("StringValue")
Reward2.Name = "Reward"
Reward2.Value = "Coins50"
Reward2.Parent = Code2

local Code3 = Instance.new("BoolValue")
Code3.Name = "Code3"
Code3.Value = false
Code3.Parent = Codes

local Reward3 = Instance.new("StringValue")
Reward3.Name = "Reward"
Reward3.Value = "Gems5"
Reward3.Parent = Code3

--Stats--

local PlayerStats = Instance.new("Folder")
PlayerStats.Name = "PlayerStats"
PlayerStats.Parent = Player

--Boosts--

local Boosts = Instance.new("Folder")
Boosts.Name = "Boosts"
Boosts.Parent = Player

local CoinsBoost = Instance.new("IntValue")
CoinsBoost.Name = "CoinsBoost"
CoinsBoost.Value = 0
CoinsBoost.Parent = Player.Boosts

local GemBoosts = Instance.new("IntValue")
GemBoosts.Name = "GemsBoost"
GemBoosts.Value = 0
GemBoosts.Parent = Player.Boosts

--Update Log and Tutorial--

local Updates = Instance.new("Folder")
Updates.Name = "Updates"
Updates.Parent = Player

local Tutorial = Instance.new("BoolValue")
Tutorial.Name = "Tutorial"
Tutorial.Parent = Updates
Tutorial.Value = true

local BETA = Instance.new("BoolValue")
BETA.Name = "BETA"
BETA.Parent = Updates

--Client Events--

wait(1)

Player.leaderstats.Level:GetPropertyChangedSignal("Value"):Connect(function()
	game.ReplicatedStorage.LeaderstatsEvents.LevelUp:FireClient(Player)
end)

Player.Rank:GetPropertyChangedSignal("Value"):Connect(function()
	game.ReplicatedStorage.LeaderstatsEvents.RankUp:FireClient(Player)
end)  

--Level System--

Player.leaderstats.Exp.Value.Changed:Connect(function()
	local RequiredExp = Player.leaderstats.Level.Value * 100 + 100
	
	if Player.leaderstats.Exp.Value == RequiredExp or Player.leaderstats.Exp.Value >= RequiredExp then
		Player.leaderstats.Exp.Value -= RequiredExp
		Player.leaderstats.Level.Value += 1
	end
end)

end)

I don’t why it doesn’t register the first 4 lines as a script.

2 Likes

Level system is at the very bottom of the script.

2 Likes

You’ve gotta be kidding me. This should be a folder.

That’s not what the problem is though because I have devproduct purchases and everything and they work.

1 Like

Could send me an example of connect it to .Changed cause I don’t know what you mean, I’ve never really used that before.

1 Like

Maybe not, but is .Changed successfully firing?

Edit: your connection is fine but changes has anargument, being the property name

1 Like

I haven’t tried because I don’t know how to do that. Could you send an example?

1 Like

Is this supposed to work? “” and not “"
local leaderstats = Instance.new(“IntValue”)

1 Like

I just changed it to a folder, I’ll check if anything changes.

1 Like
workspace.Changed:Connect(function(name)
if name == "Gravity" then 
print("The gravity is now "..workspace.Gravity
end
end)

-- im on mobile btw but this is an example
1 Like

Ok, i’ll try that. Changing leaderstats to a folder did nothing.

1 Like

Don’t use GetPropertyChangedSignal, it like never works for some reason. Just use .Changed and you should be good.

image
This line could possibly set your Exp to negative so be careful with that.

1 Like