Please give me feedback of my PunchScript

--Setting Variables
local rp = game.ReplicatedStorage
local PunchValues = rp.PunchValues
local recoil = PunchValues.Recoil
local punchCount = PunchValues.PunchCount
local moveCount = PunchValues.MoveCount
local hitNum = PunchValues.HitNum

--Variable Values
recoil.Value = 0
moveCount.Value = 1
hitNum.Value = 0

--Functions for moves and punches
local function SetMove(Player, Walk, Jump)
	--Sets the walk and jump power of player
	Player.Character.Humanoid.WalkSpeed = Walk
	Player.Character.Humanoid.JumpHeight = Jump
end
local function Hit(Player, X, Y, Z, Dmg, Waits, Movement, Jump, punchAnimation)
	--Animation
	punchAnimation:Play()
	SetMove(Player, Movement, Jump)
	punchAnimation.KeyframeReached:Connect(function(keyframeName)	
		if keyframeName ~= "Damage" then
			return
		end
		--Creates hitbox and positions it
		local hitbox = Instance.new("Part")
		local hR = Player.Character.HumanoidRootPart
		local x = hR.Position.X 
		local y = hR.Position.Y - 0.5
		local z = hR.Position.Z 
		local x2 = hR.Orientation.X
		local y2 = hR.Orientation.Y - 90
		local z2 = hR.Orientation.Z
		hitbox.Position = Vector3.new(x, y, z)
		hitbox.Orientation = Vector3.new(x2, y2, z2)
		hitbox.Size = Vector3.new(X, Y, Z)
		hitbox.CanCollide = false
		hitbox.Transparency = 0.8
		hitbox.Color = Color3.new(1, 0, 0)
		hitbox.Parent = Player.Character
		hitbox.Name = "hitbox"
		local weld = Instance.new("Weld")
		weld.Parent = Player.Character.HumanoidRootPart
		weld.Part0 = hitbox
		weld.Part1 = Player.Character.HumanoidRootPart
		weld.C1 = CFrame.new(0,0,-2)
		
		--Punch Output
		local Touched = Player.Character.hitbox.Touched:connect(function(hit)
			if hit.Name == "Hitbox" and punchCount.Value == 0 then 
				print("U")
				punchCount.Value = 1
				hit.Parent.Humanoid.Health -= Dmg
				hitNum.Value += 1
			end
		end)
		--End of Animation
		task.wait(Waits)
		Touched:Disconnect()
		hitbox:Destroy()
	end)
end

--Brawler Normal
local function Punch(player)
	--Makes sure moves dont overlap
	if recoil.Value == 1 then
		return
	end
	recoil.Value = 1
	
	--Left and right punch
	if player.leaderstats.Equipped.Value == 1 then
		if moveCount.Value == 1 then
			Hit(player, 3, 2, 3, 5, 0.3, 8, 0, player.Character.Humanoid.Animator:LoadAnimation(script.Brawler.BrawlerRightPunch))
		elseif moveCount.Value == 2 then
			Hit(player, 3, 2, 3, 5, 0.3, 8, 0, player.Character.Humanoid.Animator:LoadAnimation(script.Brawler.BrawlerLeftPunch))
		end
	end
	
	--prepares for next punch
	wait(0.6)
	moveCount.Value += 1
	recoil.Value = 0
	punchCount.Value = 0
	SetMove(player, 16, 7)
	if moveCount.Value == 3 then
		moveCount.Value = 1
	end
end

--Brawler Move 1
local function Brawler1(player)
	--Makes sure moves dont overlap
	if recoil.Value == 1 then
		return
	end
	recoil.Value = 1
	
	--Starts Timer for Gui
	moveCount.Value = 101
	
	--Move
	if moveCount.Value == 101 then
		Hit(player, 3, 2, 3, 25, 0.4, 6, 0, player.Character.Humanoid.Animator:LoadAnimation(script.Brawler.BrawlerMove1))
		SetMove(player, 16, 7)
		moveCount.Value = 1
	end
	
	--Makes sure that regular punches can be activated
	wait(1)
	recoil.Value = 0
	punchCount.Value = 0
end

--Brawler Ult
local function BrawlerU(player)
	--Makes sure moves dont overlap
	if recoil.Value == 1 then
		return
	end
	recoil.Value = 1
	
	--Starts timer for Gui
	moveCount.Value = 102
	
	--Move
	if moveCount.Value == 102 then
		Hit(player, 4, 2, 4, 50, 1, 10, 0, player.Character.Humanoid.Animator:LoadAnimation(script.Brawler.BrawlerUlt))
		SetMove(player, 10, 0)
		moveCount.Value = 1
	end
	
	--Makes sure that regular punches can be activated
	wait(0.5)
	recoil.Value = 0
	punchCount.Value = 0
end

--Detection for punches and moves
rp.Punch.OnServerEvent:Connect(Punch)
rp.Brawler1.OnServerEvent:Connect(Brawler1)
rp.BrawlerU.OnServerEvent:Connect(BrawlerU)

I need feedback on my code and I need to see if I can make any improvements to it. Im sorry if its hard to read, I just started scripting a month ago.

3 Likes

I labeled everything so it is easier to read