FindFirst Child not working in if statement

When a part is touched I wil first check if it has a value called health,but even if a part doesn’t have that it goes through the if statement:

Both don’t work:

endPoint.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("Health") then return end
end
endPoint.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Health") then

    end
end
1 Like

Are you sure the Health value exists or not in the hit.parent? Could you also show the script where you create the health value?

2 Likes

I have an npc with a health value inside it, but when something doesn’t have health the script should not follow through

1 Like

Is this a server script?(Script with RunContext Server/Legacy)? Do you have another script that removes this “Health” instance? If the script that removes the instance is a local script, you should know that

  • Local scripts only affect the player’s client. Not the server. Because of that, the server doesn’t know. You can use a RemoteEvent to communicate with the server and the client.

Let me know if this helped!

You need end) to finish the function and give it to the Connect method.

endPoint.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("Health") then return end
end)

endPoint.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Health") then

	end
end)