local DamagePart = script.Parent local Humanoid = Player.Humanoid local function DamagePlayer() DamagePart.Touched = Player.Humanoid:TakeDamage(10) end while true do wait(0.65) DamagePlayer() end
i'm trying to make a part that when touched damages the player on a loop it doesn't work though i want to put the script in the npc so it can damage the player or any npc that has the same humanoid name as the player it says unable to index nil with humanoid how to fix?
You should get the value of 'Player' because in your script is something nil. If you don't have it in your script, it will break it and it would not work.
Also, that's not how you use the Event '.Touched', Events works as a connector to a function. You should be doing this:
local DamagePart = script.Parent local db = false local number -- the amoun(in numbers) that you want for it to wait. DamagePart.Touched:Connect(function(hit) if not db then db = true if hit.Parent:FindFirstChild('Humanoid') then hit.Parent.Humanoid:TakeDamage(10) end task.wait(number) db = false end end)