¿How can i change a material during runtime in netcode? (owner authoritive)

Sorry if my english is not too god haha
So i’ve been making a Multiplayer game using Netcode for GameObjects, and i want to change the material of a object in runtime, but when i try to do that, the color doesn’t synchronize, which means that when the host changes the color, only the host can see the color, and when the client changes the color, only the client can see the color.
It’s important to mention that i change the color with a RAYCAST, and the object that shoots the raycast also has some particles that activate when the raycast is launched, but it isn’t synchronized as well.
Just in case, here’s the code for the object that changes the color of the external object:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;

public class SauceScriptTomato : NetworkBehaviour
{
    public static SauceScriptTomato inst;
    public Quaternion Pouringrot, Originalrot;
    [SerializeField] private LayerMask PickMasksauce;
    [SerializeField] private Color SauceTomatoColor, SauceHotColor, SusColor;
    public GameObject SaucePart;
    public Rigidbody rigid;
    public bool isSaucing;
    public float SauceT, PourT;
    public Transform raypos;
    public float SauceRange;
    public float rotspeed, saucespeed;
    public bool CanRot;
    public bool IsRot;

    void Awake()
    {
        inst = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        rigid = GetComponent<Rigidbody>();
    }
   
    void Update()
    {
        if (Input.GetMouseButtonDown(1) && CanRot)
        {
            IsRot = true;
        }
        else if (Input.GetMouseButtonUp(1) && CanRot)
        {
            IsRot = false;
        }

        if (IsRot)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Pouringrot, Time.deltaTime * rotspeed);
            Ray raysauce = new Ray(raypos.position, raypos.up);
            GameObject PizzaDough;
            Debug.DrawRay(raysauce.origin, raysauce.direction * SauceRange, Color.red);
            PourT += Time.deltaTime;

            if (PourT >= 0.25f)
            {
                PourT = 0.25f;
                SaucePart.SetActive(true);
            }

            if (Physics.Raycast(raysauce, out RaycastHit HitInfoSauce, SauceRange, PickMasksauce) && HitInfoSauce.transform.tag == "PizzaLay")
            {
                PizzaDough = HitInfoSauce.transform.gameObject;
                isSaucing = true;
            }
            else
            {
                isSaucing = false;
                PizzaDough = null;
            }

            if (isSaucing && PizzaDough.GetComponent<PizzaLayScript>().IsBurned == false)
            {
                saucespeed += Time.deltaTime;
                MeshRenderer meshrendpizza;
                meshrendpizza = HitInfoSauce.transform.gameObject.GetComponent<MeshRenderer>();
                if (gameObject.tag == "TomatoSauce")
                {
                    meshrendpizza.materials[1].color = Color.Lerp(meshrendpizza.materials[1].color, SauceTomatoColor, SauceT);
                    if (saucespeed >= 0.10f)
                    {
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().TomatoSauceAmount++;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().HotSauceAmount -= 1;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().SusSauceAmount -= 1;
                        saucespeed = 0f;
                    }
                }
                else if (gameObject.tag == "HotSauce")
                {
                    meshrendpizza.materials[1].color = Color.Lerp(meshrendpizza.materials[1].color, SauceHotColor, SauceT);
                    if (saucespeed >= 0.10f)
                    {
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().HotSauceAmount++;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().TomatoSauceAmount -= 1;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().SusSauceAmount -= 1;
                        saucespeed = 0f;
                    }
                }
                else if (gameObject.tag == "SusSauce")
                {
                    meshrendpizza.materials[1].color = Color.Lerp(meshrendpizza.materials[1].color, SusColor, SauceT);
                    if (saucespeed >= 0.10f)
                    {
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().SusSauceAmount++;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().HotSauceAmount -= 1;
                        HitInfoSauce.transform.GetComponent<PizzaLayScript>().TomatoSauceAmount -= 1;
                        saucespeed = 0f;
                    }
                }
               
            }
        }
        else
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Originalrot, Time.deltaTime * rotspeed);
            PourT = 0f;
            SaucePart.SetActive(false);
        }

        if (rigid.useGravity == true)
        {
            CanRot = false;
            transform.rotation = Originalrot;
            PourT = 0f;
            SaucePart.SetActive(false);
            IsRot = false;
        }
    }


    [ServerRpc(RequireOwnership = false)]
    public void GiveOwnershipServerRpc(ulong clientId)
    {
        GetComponent<NetworkObject>().ChangeOwnership(clientId);
    }

Any clue on what’s going on? Everything is welcome!

I don’t see where you are synchronizing this change. There is one ServerRpc and that’s for changing ownership, but I don’t see where that’s being called. The rest of the code doesn’t concern itself at all with synchronizing network state.

Btw DRY principle! Instead of repeating this over and over again:
HitInfoSauce.transform.GetComponent<PizzaLayScript>()

Put it in a variable and use that. More readable code, and faster:
var pizzaLay = HitInfoSauce.transform.GetComponent<PizzaLayScript>();

Hi there! Thanks for your response! So the ServerRpc for the ownership gets called on the player script, so it doesn’t show up there, but it does work.
The problem is that the material change doesn’t get synchronized, i tried to make another ServerRpc for changing the color and it did work on the host, since he can see the changes that the client does, but the client can’t see the changes that the host does. Any suggestion?

btw i ended up using your suggestion, now my code looks nice hahah

I forgot to mention that there are some variables that this script changes for the other script called “PizzaLayScript”, but they don’t change if the client tries to, however the host can do that.