Hey Guys so I’m working on a One Piece Inspired game and I decided that I’ll give away some of the scripts that I’ve made, here’s the Under Water Effect, I will also explain it below…
https://gyazo.com/5c1e44854ce749572b991d231afd580b
local cam = workspace.CurrentCamera
while true do
wait()
if cam.CFrame.Y < -0.3 then
local Info = TweenInfo.new(0.3)
local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=0.3})
Tween:Play()
local Info2 = TweenInfo.new(0.3)
local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=10})
Tween2:Play()
elseif cam.CFrame.Y > -0.3 then
local Info = TweenInfo.new(0.3)
local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
Tween:Play()
local Info2 = TweenInfo.new(0.3)
local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=0})
Tween2:Play()
end
end
This is what you need to put in the ScreenGui, basically create a ScreenGui then inside of that ScreenGui add a Frame, make sure to set the size of it to (1,0,1,0) this is in case you want your game to be cross platform, furthermore make the frame a blue-ish tent and make the transparency of it to 0
In Lighting insert a BlurEffect, then rename it whatever you want, but if you are new to scripting then you should just change it to ‘UnderWaterBlur’ Like I have in my game so that the script works first try, change the Size of the blur to 0 in the properties section
This bit of the code basically detects if the camera is below -0.3 studs on the Y axes, you can change that number based on the water level, it will take a bit of testing but trust the process, furthermore after it detects if the camera is below Y -0.3 it tweens the Frame’s Transparency and also it tweens the Blur Size.
if cam.CFrame.Y < -0.3 then
local Info = TweenInfo.new(0.3)
local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=0.3})
Tween:Play()
local Info2 = TweenInfo.new(0.3)
local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=10})
Tween2:Play()
In this bit of code, the code detects if the camera is above the Y axes of -0.3, and if it is then it tweens the Blur Size and the Frame Transparency, it basically reverts the effects.
elseif cam.CFrame.Y > -0.3 then
local Info = TweenInfo.new(0.3)
local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
Tween:Play()
local Info2 = TweenInfo.new(0.3)
local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=0})
Tween2:Play()
end
I hope you guys found this helpful!