I managed to fix it. I'm leaving a small explanation for anyone else with a similar problem.
I removed the food counter and instead made it a new function. Then added a rpc call to it. So the whole code looks like this.
puppet var food = 10
func addfood():
food += 20
func calc_food():
rpc("sync_food")
remotesync func sync_food():
rset("food", food)
rpc("sync_counter")
remotesync sync_counter():
$Foodcounter.text = str(food)
func _on_Button_pressed():
addfood()
calc_food()
I still don't understand why this one works and the previous one doesn't.
So what's happening here. When I press the button, the addfood puts +20 on the var food in server side. Then calc_food(this func is probably redundant) gets called, it calls a remote func sync_food that executes both client and server side which changes the var food, to the current food. Since puppet var food can only be changed by server, the client now has the same food as the server.
Then the visual $Foodcounter node shows the current food in text.
The only difference in my code is that the
$Foodcounter.text = str(food)
gets called in it's own function instead of in the same function right after syncing food. Why this makes a difference I still don't know.
I consider this problem solved although I don't 100% get what was causing the problem.