Requirement is not increasing

Hello! Im making it so that after 10 counts of training, the requirement to level up gets added by 5.

However, this isn’t working, and I don’t know why! After the first 10 punches of training, they level up only after 5 punches each time.

There are no errors in the output. Can someone help?

Thank you.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local PlayerMod = require(plr.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerMod:GetControls()

local UIS = game:GetService("UserInputService")

local animator = hum:WaitForChild("Animator")
local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
local rightPunch = animator:LoadAnimation(script:WaitForChild("RightPunch"))
local punch = "left"

local power = char:FindFirstChild("PunchPower") or char:WaitForChild("PunchPower")

local count = 0
local debounce = false

game.ReplicatedStorage.StartTraining.OnClientEvent:Connect(function()
	local requirement = power.Value + 5
	Controls:Disable()
	plr.PlayerGui.StopTraining.TextButton.Visible = true
	UIS.InputBegan:Connect(function(input, gpe)
		if gpe then return end
		if debounce then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if punch == "left" and not debounce then
				count += 1
				debounce = true
				rightPunch:Play()
				task.wait(.55)
				punch = "right"
				debounce = false
			elseif punch == "right" and not debounce then
				count += 1
				debounce = true
				leftPunch:Play()
				task.wait(.7)
				punch = "left"
				debounce = false
			end

			print(count, requirement)

			if count == requirement then --the requirement is added by 5 each time they
				--[continued from above] - gain 1 punch power
				script.LevelUp:Play()
				requirement += 5 --this doesn't add the requirement by 5 each time they level up. 
				print(count, requirement)
				print('gained one punch power')
				game.ReplicatedStorage.AddPower:FireServer()
			end 
		end
	end)
end)

plr:FindFirstChild("PlayerGui"):FindFirstChild("StopTraining"):FindFirstChild("TextButton").MouseButton1Click:Connect(function()
	game.ReplicatedStorage.StartTraining:FireServer()
	Controls:Enable()
	plr.PlayerGui.StopTraining.TextButton.Visible = false
end)
1 Like

You need to reset count every time you level up, or else they only need to get 5 more to level up to the next level since the cap increase by 5.

How do i make it so that the requirement is added exponentially? Basically if the requirement was 10, then the requirement would be 16 (10+16 = 6), then 23 (16+7 = 23) , then 31 (23+8 = 31)

You would store the current level and you would set the requirement to `requirement = 10 + math.pow(2, level)`` or something like that. This example makes it go 10, 12, 14, 18, 26, 42, 74, 138, …