I wanted to try to make a damage script for when an npc touches a player they take damage. So I wrote my own script but it only damaged the player once. When I wrote it differently it didn’t damage the player at all.
Desperate for help I looked up on the dev forum or youtube tutorials but none of them worked or was related to what I wanted to add.
Here is the script I used. Its not really my own because I tried to look on dev forum and youtube for help. But yeah, you get the idea.
--local lhand = script.Parent.LeftHand
local rhand = script.Parent.RightHand
local function onTouch(otherPart)
local hum = otherPart.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(10)
end
end
torso.Touched:Connect(onTouch)
rhand.Touched:Connect(onTouch)
lhand.Touched:Connect(onTouch)