Changing colors and scales problem :(

Hello everybody,
I’m new to blender and Python coding and I want some help please…
actually I’m working on a chemical game where I have to change colors and scales of some objects.
The problem is when I execute the script that I coded for these changes, it does not apply in “player mode”, but I can see the changes when I exit this mode.
I want please a solution that I can see the changes at real time in the game.
Here’s the code I made for the scale changing :

import bpy

for ob in bpy.data.objects:
    if ob.name == 'blue':
        ob.scale.z -= .02
        ob.location.z -= .02
        a = ob.scale.z
        if a < 0.5 :
            break
    if ob.name == 'red':
        ob.scale.z += .02
        ob.location.z += .02
        

Thanks in advance.