I've tried numerous scripts and they aren't working? Can anyone please help??
01 | function DisableDoors(player) |
02 | player.PlayerGui.TrainDriveGui.Screen.JunctionsTab.LeftDoors.LocalScript.Disabled = true |
03 | player.PlayerGui.TrainDriveGui.Screen.JunctionsTab.RightDoors.LocalScript.Disabled = true |
04 | end |
05 |
06 | function EnableDoors(player) |
07 | player.PlayerGui.TrainDriveGui.Screen.JunctionsTab.LeftDoors.LocalScript.Disabled = false |
08 | player.PlayerGui.TrainDriveGui.Screen.JunctionsTab.RightDoors.LocalScript.Disabled = false |
09 | end |
10 |
11 | if script.Parent.BodyVelocity.Velocity = = Vector 3. new( 0 , 0 , 0 ) then |
12 | EnableDoors() |
13 | else |
14 | DisableDoors() |
15 | end |
It is because the "if" statement only runs one time, consider putting it in a loop like this:
1 | repeat |
2 | if script.Parent.BodyVelocity.Velocity = = Vector 3. new( 0 , 0 , 0 ) then |
3 | EnableDoors() |
4 | else |
5 | DisableDoors() |
6 | end |
7 | wait() |
8 | until 1 = = 0 |
Instead of:
1 | if script.Parent.BodyVelocity.Velocity = = Vector 3. new( 0 , 0 , 0 ) then |
2 | EnableDoors() |
3 | else |
4 | DisableDoors() |
5 | end |
which could only be ran once.
Edit (Suggested by Sarcadistic): As they mentioned, you could use a .Changed event:
1 | script.Parent.Changed:connect( function () |
2 | if script.Parent.BodyVelocity.Velocity = = Vector 3. new( 0 , 0 , 0 ) then |
3 | EnableDoors() |
4 | else |
5 | DisableDoors() |
6 | end |
7 | end ) |