Hitting doesnt take away damage from the player

Hey guys! I’m trying to get over this issue I have, it’s basically a hit script that will stun and take away health from the player; problem is, it stuns, but does not take away any health, making them walk away unharmed; besides being frozen. I don’t really know what to do besides what I have put here.

local hurtie = 30

script.Parent.Touched:Connect(function(touch)

touch.Parent.HumanoidRootPart.Anchored = true

wait(2)

touch.Parent.HumanoidRootPart.Anchored = false

local h = touch.Parent.Humanoid

h:TakeDamage(hurtie)

end)

Maybe this will work

local hurtie = 30

script.Parent.Touched:Connect(function(touch)

if touch and touch.Parent and touch.Parent:FindFirstChild("Humanoid") then

touch.Parent.HumanoidRootPart.Anchored = true

--takes damage before unfrozen

touch.Parent.Humanoid.Health -= 30

wait(2)

touch.Parent.HumanoidRootPart.Anchored = false

end

end)
1 Like

For some reason, in my studio, the code seems to work fine. I recommend checking if touch parent has a humanoid like Dolphin_Worm did though.

1 Like