Not working properly punching system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So, i can punch from the side but not from the front.

  2. What is the issue? Include screenshots / videos if possible!
    The punching system that I found on youtube is a little buggy.
    I can’t make it work properly. As you can see in the video, I have to stand properly next to the NPC to punch him. The points counter also broke but i think i will fix it.


    i’m asking for help because i don’t understand rays that much

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, i looked on developer hub. tried fixing it my self and Tried also ChatGPT but it kinda broke it more.

So this is the code on the server side. i located the problem between line 46 and line 52. Everything else should work normally. if you want you can also give me some feedback.
Can someone help me fix it?

local SS = game:GetService("SoundService")
local RSFolder = game.ReplicatedStorage:WaitForChild("CombatSystem")
local Config = script:WaitForChild("Settings")

game.Players.PlayerAdded:Connect(function(Player: Player)
	Player.CharacterAdded:Connect(function(Character: Model)
		local CombatStatus = Instance.new("StringValue", Character)
		CombatStatus.Name = "CombatStatus"
		CombatStatus.Value = ""
		
		local Hitbox = Instance.new("Part", Character.HumanoidRootPart)
		local WeldConstraint = Instance.new("WeldConstraint", Hitbox)
		
		WeldConstraint.Part0 = Hitbox
		WeldConstraint.Part1 = Character.HumanoidRootPart
		
		Hitbox.Name = "CombatSystemHitbox"
		Hitbox.Anchored = false
		Hitbox.Massless = true
		Hitbox.CanCollide = false
		Hitbox.Transparency = 1
		Hitbox.Size = Vector3.new(6, 6, 5.5)
		Hitbox.Color = Color3.new(1, 0, 0)
		Hitbox.Position = Character.HumanoidRootPart.Position
		Hitbox:PivotTo(Character.HumanoidRootPart.CFrame)
	end)
end)

RSFolder.CombatEvent.OnServerEvent:Connect(function(Player: Player, EventType: string, Argument1: string)
	local Character = Player.Character
	
	if EventType == "M1" and Character.CombatStatus.Value == "" then
		Character.CombatStatus.Value = "Attacking"
		
		local Animation = script.Animations:FindFirstChild(Argument1.."_R15")
		--[[if Character.Humanoid.RigType == Enum.RigType.R15 then
			Animation = script.Animations:FindFirstChild(Argument1.."_R15")
		else
			Animation = script.Animations:FindFirstChild(Argument1.."_R6")
		end]]--
		
		local AnimationTrack = Character.Humanoid:LoadAnimation(Animation)
		AnimationTrack:Play()
		SS["MissedPunch"]:Play()
		
		local StartPosition = Character.HumanoidRootPart.CombatSystemHitbox.Position
		local Direction = Character.HumanoidRootPart.CombatSystemHitbox.CFrame.LookVector
		local RayCastParams = RaycastParams.new()
		RayCastParams.FilterType = Enum.RaycastFilterType.Exclude
		RayCastParams.FilterDescendantsInstances = {Character:GetDescendants()}

		local Ray = game.Workspace:Raycast(StartPosition, Direction * 3, RayCastParams)
		
		if Ray and Ray.Instance and Ray.Instance.Parent:FindFirstChild("Humanoid") then
			task.wait(0.3)
			local EnemyCharacter = Ray.Instance.Parent
			local IsAttackable = EnemyCharacter:FindFirstChild("IsAttackable")
			if IsAttackable then
				if IsAttackable.Value == true then
					EnemyCharacter.Humanoid:TakeDamage(Config.Damage.Value)
					if EnemyCharacter.Humanoid.Health <= 0 then
						if IsAttackable.KillPoints then
							if not IsAttackable.HasBeenKilled.Value then
								IsAttackable.HasBeenKilled.Value = true
								IsAttackable.HasBeenKilled.Creator.Value = Character
								Player.leaderstats.Points.Value += EnemyCharacter.IsAttackable.KillPoints.Value
								RSFolder.KillEvent:FireClient(Player, EnemyCharacter)
							end
						end
					else
						SS["Punch"]:Play()
					end
				end
			end
		end
		AnimationTrack.Ended:Connect(function()
			Character.CombatStatus.Value = ""
		end)
	end
end)

its probably because the punch hitbox ends too soon so try to change the wait times

i don’t think thats hitbox fault. its the rays fault probably because its not rotating or something. hitbox is for enemy

Ok i’m dumb. So, i forgot to add hitboxes to NPCs that why it didn’t work properly.

then mark this post as solved .

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.