Changing the delta (friction) of move_toward from one frame to the next

Godot Version

v4.1.3

Question

I’m attempting to create ice hazard tiles in a 2D platformer. When the player is on an ice tile the friction for deceleration drops from 200 to 20. Unfortunately when the player slide off of an ice block, the friction does not reset until they come to a complete stop, leading them to “slide” on regular ground. I would like the friction to reset the same frame that the player leaves the ice.

A simplified version of my code (ommited code mentioned in comments) is below. Can anyone see where I’m going wrong with this?

var friction = 200 # set default value

func _physics_process(delta):
    if direction: # Retrieved from Input
        velocity.x = direction * move_speed
    else: 
        velocity.x = move_toward(velocity.x, 0, friction)

    move_and_slide()

    for i in range(get_slide_collision_count):
         var collision = get_slide_collision(i)
         var cell = tilemap.local_to_map(collision.get_position() - collision.get_normal() - Vector2(1,0))
         var tileData: TileData = tilemap.get_cell_tile_data(0, cell)
         if tileData:
             var terrainInt = tileData.get_custom_data("Terrain") # tileData is a TileData object retrieved from tile map
             if terrainInt == 1: # Tile is ice
                friction = 20
             else:
                friction = 200

Where do you get tileData from?

I got it from the slide collision. I had omitted that code for simplicity, but have now gone back and edited the question to add it.