Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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?

01while true do
02    wait(0.3) -- To reduce intense lag
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!')
06        else
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 = UDim2.new(1,0,1,0)
11            waterEffect.BackgroundColor3 = Color3.new(0,0,1)
12            waterEffect.BackgroundTransparency = .7
13        end
14    else
15        if not game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild('WaterEffect') then
View all 22 lines...

Thanks! :)

Edit 2: Fixed grammar in the print()'s

0
Maybe make a variable for CurrentCamera so the script doesn't have to find it in workspace over and over again. User#11440 120 — 8y
0
Perhaps you should use RunService.RenderStepped instead of a while loop. ShadowsDev 62 — 8y

Answer this question