Problem with not taking damage when hit

i’m trying to make a punch move.

the way i do this is by checking in a localscript when E is pressed and then firing a remote event

in the serverscript i clone a part and make a weld and put the part infront of the player
then when the part gets hit i make the person who got hit take damage

but for some reason when i try to hit myself in a local server there’s only like a 5% chance it works

on a dummy it works fine but when i try to do it on myself it doesn’t

i have tried to check if the hit.parent was a model but that didn’t work

localscript inside of StarterPlayerScripts:

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage.Events.Event


UIS.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.E then
		event:FireServer()
	end	
end)

serverscript inside of serverscript service:

local event = game.ReplicatedStorage.Events.Event
local poepleHit = {}

event.OnServerEvent:Connect(function(player)
	local hitbox = game.ReplicatedStorage.HitBoxes.Part:Clone()
	local weld = Instance.new("Weld")

	hitbox.Parent = game.Workspace

	weld.Parent = player.Character.HumanoidRootPart
	weld.Part0 = weld.Parent
	weld.Part1 = hitbox
	weld.C1 = weld.C0 - weld.C0.Position + Vector3.new(0, 0, 3)

	hitbox.Touched:Connect(function(hit)
		local damage = 5
		if hit.Parent ("Humanoid") and not table.find(poepleHit, hit.Parent) then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
			table.insert(poepleHit, hit.Parent)
		end
	end)
	wait()
	hitbox:Destroy()
	table.clear(poepleHit)
end)
1 Like

Maybe try using Raycast for a better detection.

maybe try inserting hit.Parent.Name instead of hit.Parent because it might block it from doing stuff, also do hit.Parent:FindFirstChild(“Humanoid”)

i changed it to the changements to the serverscript

local event = game.ReplicatedStorage.Events.Event
local poepleHit = {}

event.OnServerEvent:Connect(function(player)
	local hitbox = game.ReplicatedStorage.HitBoxes.Part:Clone()
	local weld = Instance.new("Weld")

	hitbox.Parent = game.Workspace

	weld.Parent = player.Character.HumanoidRootPart
	weld.Part0 = weld.Parent
	weld.Part1 = hitbox
	weld.C1 = weld.C0 - weld.C0.Position + Vector3.new(0, 0, 3)

	hitbox.Touched:Connect(function(hit)
		local damage = 5
		if hit.Parent ("Humanoid") and not table.find(poepleHit, hit.Parent.Name) then
			hit.Parent.Humanoid:TakeDamage(damage)
			table.insert(poepleHit, hit.Parent.Name)
		end
	end)
	wait()
	hitbox:Destroy()
	table.clear(poepleHit)
end)

omg my first solution that ive ever gotten im happy