Need help with my punch system

Hello, I want to make a training system that increases the player’s punch damage +1 When punching a mesh, so does anyone know how can i make it? Please message me if u can help.

The Punching System Script

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local punchAnimation = Instance.new(“Animation”)
punchAnimation.AnimationId = “rbxassetid://18100063619” – Replace with your animation asset ID

local punchTrack = humanoid:LoadAnimation(punchAnimation)

– Sound settings
local punchSoundId = “rbxassetid://5835032207” – Replace with your punch sound asset ID
local punchSound = Instance.new(“Sound”, character)
punchSound.SoundId = punchSoundId

– Cooldown settings
local canPunch = true
local punchCooldown = 1 – 1 second cooldown

– Initial damage amount
local damageAmount = 10
local damageRadius = 5

– Function to find enemies within the workspace
local function findEnemies()
local enemies = {}

for _, model in ipairs(workspace:GetChildren()) do
	if model ~= character and model:FindFirstChild("Humanoid") then
		table.insert(enemies, model)
	end
end

return enemies

end

local function dealDamage()
local enemies = findEnemies()

for _, enemy in ipairs(enemies) do
	local enemyHumanoid = enemy:FindFirstChild("Humanoid")
	if enemyHumanoid then
		enemyHumanoid:TakeDamage(damageAmount)
	end
end

end

local function onScreenClick()
if canPunch then
canPunch = false

	-- Play the punch animation
	punchTrack:Play()

	-- Play the punch sound
	punchSound:Play()

	-- Deal damage to nearby enemies
	dealDamage()

	-- Set a cooldown before the player can punch again
	wait(punchCooldown)
	canPunch = true
end

end

– Detect mouse clicks
local userInputService = game:GetService(“UserInputService”)

userInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
onScreenClick()
end
end)

1 Like

please format your code properly.

2 Likes

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local punchAnimation = Instance.new(“Animation”)
punchAnimation.AnimationId = “rbxassetid://18100063619” – Replace with your animation asset ID

local punchTrack = humanoid:LoadAnimation(punchAnimation)

– Sound settings
local punchSoundId = “rbxassetid://5835032207” – Replace with your punch sound asset ID
local punchSound = Instance.new(“Sound”, character)
punchSound.SoundId = punchSoundId

– Cooldown settings
local canPunch = true
local punchCooldown = 1 – 1 second cooldown

– Initial damage amount
local damageAmount = 10
local damageRadius = 5

– Function to find enemies within the workspace
local function findEnemies()
local enemies = {}

for _, model in ipairs(workspace:GetChildren()) do
	if model ~= character and model:FindFirstChild("Humanoid") then
		table.insert(enemies, model)
	end
end

return enemies

end

local function dealDamage()
local enemies = findEnemies()

for _, enemy in ipairs(enemies) do
	local enemyHumanoid = enemy:FindFirstChild("Humanoid")
	if enemyHumanoid then
		enemyHumanoid:TakeDamage(damageAmount)
	end
end

end

local function onScreenClick()
if canPunch then
canPunch = false

	-- Play the punch animation
	punchTrack:Play()

	-- Play the punch sound
	punchSound:Play()

	-- Deal damage to nearby enemies
	dealDamage()

	-- Set a cooldown before the player can punch again
	wait(punchCooldown)
	canPunch = true
end

end

– Detect mouse clicks
local userInputService = game:GetService(“UserInputService”)

userInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
onScreenClick()
end
end)