Do you have collision objects set correctly? E.g. does Mask
property of fence matches Group
of sheep and vice versa? Put a simple print inside your code and check if collision happens
Ahh, yes, I see you also made another post with a video, the approach is problematic:
Print out the values you are setting (or use debugging to investigate them)