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

I'm making a XP system but it keeps saying something is wrong help?

So this is my code for my game

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local EXP = Instance.new("NumberValue", leaderstats)
	EXP.Name = "EXP"
	
	local Lvl = Instance.new("NumberValue", leaderstats)
	Lvl.Name = "Level"
	Lvl.Value = 1
	
	local MaxEXP = 100 * (Lvl.Value / 2)
	
	game.ServerStorage.GiveExp.Event:Connect(function(amount,plr)
		if player.Name == plr.Name then
			EXP.Value = EXP.Value + amount
		end
	end)
	EXP:GetPropertyChangedSignal("Value"):Connect(function()
		if EXP.Value >= MaxEXP.Value then
			EXP.Value - MaxEXP.Value
			Lvl.Value = Lvl.Value + 1
		end
	end)
end)

and its saying this segment is wrong

EXP.Value - MaxEXP.Value

I don't really understand why it's doing that and how to fix it

1 answer

✓ Accepted answer

This is because you’re performing a blank arithmetic. To actively modify a state, you have to apply the = assign operator.

EXP.Value = (EXP.Value - MaxEXP.Value)

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