How to add a GUI when camera is Y <= 0? [Not efficient enough]
Asked by
8 years ago Edited 8 years ago
I'm trying to create a script, when you are below the water, a blue GUI appears. The issue is that this script doesn't seem very efficient. I've tried this with the CurrentCamera, the Changed function, but it did nothing and I didn't find any other function. Is there a way to reduce the lag of this script?
03 | if game.Workspace.CurrentCamera.CFrame.Y < = 0 then |
04 | if game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild( 'WaterEffect' ) then |
05 | print ( 'GUI exists while the player is underwater, all good!' ) |
07 | print ( "GUI doesn't exist while the player is underwater and should be, creating a GUI.." ) |
08 | local waterEffect = Instance.new( 'Frame' , game.Players.LocalPlayer.PlayerGui.ScreenGui) |
09 | waterEffect.Name = 'WaterEffect' |
10 | waterEffect.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
11 | waterEffect.BackgroundColor 3 = Color 3. new( 0 , 0 , 1 ) |
12 | waterEffect.BackgroundTransparency = . 7 |
15 | if not game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild( 'WaterEffect' ) then |
16 | print ( 'No GUI while the player is the air, all good!' ) |
18 | print ( 'The player is in the air and the GUI needs to be removed.' ) |
19 | game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild( 'WaterEffect' ):Destroy() |
Thanks! :)
Edit 2: Fixed grammar in the print()'s