ServerScriptService.Script:7: attempt to index nil with 'Humanoid

im new to for _, v in pairs do so i dont know what wrong with the script

script:

local part = game.Workspace.Part:GetChildren()
local plr = game.Players.PlayerAdded:Connect(function(plr)


	for  _, v in pairs(part) do
		v.Touched:Connect(function()
			plr.Character.Humanoid:TakeDamage(10)		
		end)
	end
end)

also its a normal script

Why use game playeradded when it’s directly defined in the touched function?

for _,v in pairs(game.Workspace.Part:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(10)
end
end
1 Like

i forgot hit.Parent existed sorry

1 Like