WiFi connected but not working after a while, unless i turn it off and on again (macosx sierra)

Go to Network in System Preferences. Go to Advanced, and check the DNS Servers. You should have 8.8.8.8 and 8.8.4.4, add those if they are not on there. Now check if your ipv4 is set to DHCP, and turn off ipv6 if it is on.