Hello Scruffy86! I think I might know where the problem is:
Line 11 that reads "$SpawnedTurrets=1" should instead be "SpawnedTurrets=1"
You only need to use the "$" before a variable name if it is part of an if statement, or if it is being used as a value in another statement, for example "if $global.maxHP >= 120" or "player setmaxhp $global.maxHP". When setting a variable (or when modifying it) you do NOT use the "$" symbol!
Also, you have two variables with the same name for some reason? One is a local variable called "SpawnedTurrets" and the other is a map variable called "map.SpawnedTurrets". This might not be a problem, but I would change one of those variables so that they aren't so similar. It will almost surely lead to confusion later!