I would like that when there are more than 3 zombies in the game the barrier becomes transparent and when there are less than 3 it comes back to 0.8 transparency but my script not work and I dont understand why. Can you help me please?
Sorry I dont speak english i'm Québecker and I have 16 years old so I don't perfectly speak in english:/
"/900" because the "i" return +10100 value
01 | while wait() do |
02 | local ZombiesInGame = workspace.Zombies_Folder:GetChildren() |
03 | local safezone = true |
04 |
05 | if #ZombiesInGame > 3 and safezone then |
06 | safezone = false |
07 | workspace.GamePlayersStats.SafeZone.Script.Disabled = true |
08 | for _, v in pairs (workspace.GamePlayersStats.Laser_SafeZone:GetChildren()) do |
09 | for i = 0 , 25 do |
10 | v.Transparency = v.Transparency - i/ 900 |
11 | print (i) |
12 | wait() |
13 | end |
14 | end |
15 | elseif #ZombiesInGame < 3 and not safezone then |
Okay, first of all...
You don't have to use the safezone
value. I see no use for it in the script other than a marker. Unless it is for debugging, I advise you to remove it.
Second - your fade in/out loops are incorrect. The correct code (without safezone
):
01 | while wait() do |
02 | local ZombiesInGame = workspace.Zombies_Folder:GetChildren() |
03 |
04 | if #ZombiesInGame > 3 and safezone then |
05 | workspace.GamePlayersStats.SafeZone.Script.Disabled = true |
06 | for _, v in pairs (workspace.GamePlayersStats.Laser_SafeZone:GetChildren()) do |
07 | for i = 0 , 24 do |
08 | v.Transparency = v.Transparency - 0.032 -- This is how much it should fade out in each iteration |
09 | print (i) |
10 | wait() |
11 | end |
12 | end |
13 | elseif #ZombiesInGame < 3 and not safezone then |
14 | workspace.GamePlayersStats.SafeZone.Script.Disabled = false |
15 | for _, v in pairs (workspace.GamePlayersStats.Laser_SafeZone:GetChildren()) do |