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)