Why players lagging when they auto level up?

local script:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local RS = game:GetService("ReplicatedStorage")

local stats = Player:WaitForChild("stats")
local Rank = stats.Rank

local RS = game:GetService("ReplicatedStorage")

local AutoEvent = RS.Remotes.Layers.AutoLevelUpEvent

local Value = script.Parent.Value -- (bool value)

script.Parent.MouseButton1Click:Connect(function()
	while Value.Value == true do
		wait(.5)
		AutoEvent:FireServer()
	end
end)

EventScript:

local RS = game:GetService("ReplicatedStorage")
local Event = RS.Remotes.Layers.AutoLevelUpEvent

Event.OnServerEvent:Connect(function(plr)
	local leaderstats = plr:WaitForChild("leaderstats")
	local stats = plr:WaitForChild("stats")
	local Prices = plr:WaitForChild("Prices")
	local Upgrades = plr:WaitForChild("Upgrades")
	local LevelUpPrice = Prices:WaitForChild("LevelUpPrice")
	local LevelUpPriceUpgrade = Upgrades:WaitForChild("LevelUpPriceUpgrade")
	local Coins = leaderstats.Coins
	local Level = leaderstats.Level
	local Rank = stats.Rank
	local Crystals = stats.Crystals
	local Multi 
	local LevelPrice
	
	
	if LevelUpPriceUpgrade.Value >= 1 then
		LevelPrice = 100 - 5 * LevelUpPriceUpgrade.Value
	else
		LevelPrice = 100
	end

	if Crystals.Value <= 2 then
		Multi = 1.5
	elseif Crystals.Value >= 3 and Crystals.Value <= 7 then
		Multi = 1.45
	elseif Crystals.Value >= 7 then
		Multi = 1.4
	end

	local function UpdateLevelUpPrice()
		LevelUpPrice.Value = (LevelPrice * (Multi^Level.Value))
	end

if Rank.Value >= 2 and Level.Value >= 0 then
		UpdateLevelUpPrice()
		if Coins.Value >= LevelUpPrice.Value then
			Level.Value += 1
			if Rank.Value < 4 then
			Coins.Value -= LevelUpPrice.Value
			else
				Coins.Value = Coins.Value
			end
			UpdateLevelUpPrice()
		end
	end
end)

players start lagging when they doing auto level up
can anyone help?

In your script, it appears that you have a while loop. Are you sure that this loop eventually breaks? In which I mean Value.Value will equal to false at some point?

Value.Value = BoolValue.Value
need more characters aaaaaaaa

when value equals to false auto level up stops