Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why am I not getting levels when I hit a certain amount of EXP?

I made a script that looks like this:

if player.leaderstats.EXP.Value >= 1500 then player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1 player.leaderstats.EXP.Value = player.leaderstats.EXP.Value - 1500 end

I made it so when the player's exp is greater than or equal to 1500, you increase by a level, but for some reason I am just piling up EXP without it turning into levels, I even tried to fix it but it ended up just deleting all my EXP and keeping my level at 1.

I will give you my leaderstats script if that will help you answer my question in any way, shape or form:

local dataStores = game:GetService("DataStoreService"):GetDataStore("LeaderstatsDataStore")

local defaultCash = 0 local defaultEXP = 0 local defaultLevel = 1 local playersLeft = 0

game.Players.PlayerAdded:Connect(function(player)

playersLeft = playersLeft + 1

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

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

local EXP = Instance.new("IntValue")
EXP.Name = "EXP"
EXP.Value = 0
EXP.Parent = leaderstats

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

local playerData = Instance.new("Folder")
playerData.Name = player.Name
playerData.Parent = game.ServerStorage.PlayerData

local equipped = Instance.new("StringValue")
equipped.Name = "Equipped"
equipped.Parent = playerData

local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = playerData

if player.leaderstats.EXP.Value >= 1500 then player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1 player.leaderstats.EXP.Value = player.leaderstats.EXP.Value - 1500 end

1 comment

0

Can you fix the lua box, please? Some code is outside of it

1 answer

✓ Accepted answer

The problem is you're only checking once the script starts running and that's it, you never check again, so what I would do is put an event listener that will run every time the value of 'Exp' changes, which is going to look something like this:

EXP:GetPropertyChangedSignal("Value"):Connect(function()
	if player.leaderstats.EXP.Value >= 1500 then 
		player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1 	
		player.leaderstats.EXP.Value = player.leaderstats.EXP.Value - 1500 
	end
end)

More on GetPropertyChangedSignal

Just put this block of code somewhere under the PlayerAdded event that you have after you define the variable "EXP" and it should work fine

Note: please make sure that you put your code in code blocks and format your question in a neat way so more people would be willing to help you out

Hope I helped, please let me know if you have further questions!

1 comment

0

Thank you so much for the answer and feedback, it really helped! Have a good day!

This discussion is preserved as it was. New answers, comments, and votes are closed.