Originally made for this post: Help on a water blur script
<Script> - StarterPlayerScripts Localscript
local DetectTerrainWater = true
local UnderwaterReverb = true
local DetectPartWater = true
local TouchPart = Instance.new("Part", workspace)
TouchPart.Anchored = true
TouchPart.CanCollide = false
TouchPart.Size = Vector3.new(1, 1, 1)
TouchPart.Transparency = 1
TouchPart.Name = "TouchPart"
local Blur = Instance.new("BlurEffect", game.Lighting)
Blur.Enabled = false
local ColorCorrection = Instance.new("ColorCorrectionEffect", game.Lighting)
ColorCorrection.Enabled = false
ColorCorrection.TintColor = Color3.fromRGB(11, 143, 213)
ColorCorrection.Contrast = 0.5
ColorCorrection.Brightness = 0.4
ColorCorrection.Saturation = 0.6
local UnderwaterAmbienceSound = Instance.new("Sound", workspace.CurrentCamera)
UnderwaterAmbienceSound.Name = "UnderwaterAmbienceSound"
UnderwaterAmbienceSound.SoundId = "rbxassetid://4626145950"
if not UnderwaterAmbienceSound.IsLoaded then
UnderwaterAmbienceSound.Loaded:Wait()
end
UnderwaterAmbienceSound.Volume = 0
UnderwaterAmbienceSound.Looped = true
UnderwaterAmbienceSound:Play()
local TouchConnection = TouchPart.Touched:Connect(function() end)
local LastReverb = nil
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
local WaterFound = false
if DetectTerrainWater then
local min = workspace.CurrentCamera.CFrame.Position - (4 * Vector3.new(1, 1, 1))
local max = workspace.CurrentCamera.CFrame.Position + (4 * Vector3.new(1, 1, 1))
local region = Region3.new(min, max)
local materials, occupancies = workspace.Terrain:ReadVoxels(region, 4)
local size = materials.Size
for x = 1, size.X, 1 do
for y = 1, size.Y, 1 do
for z = 1, size.Z, 1 do
if materials[x][y][z].Name == "Water" then
WaterFound = true
break
end
end
end
end
end
if not WaterFound and DetectPartWater then
TouchPart.CFrame = workspace.CurrentCamera.CFrame
local TouchingParts = TouchPart:GetTouchingParts()
for _, Part in pairs(TouchingParts) do
if Part.Name:lower():find("water") or Part.Parent.Name:lower():find("water") then
WaterFound = true
break
end
end
end
if WaterFound then
if UnderwaterReverb then
if game.SoundService.AmbientReverb ~= Enum.ReverbType.UnderWater then LastReverb = game.SoundService.AmbientReverb end
game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
end
UnderwaterAmbienceSound.Volume = 0.5
ColorCorrection.Enabled = true
Blur.Enabled = true
else
if UnderwaterReverb then
game.SoundService.AmbientReverb = LastReverb or Enum.ReverbType.NoReverb
end
UnderwaterAmbienceSound.Volume = 0
ColorCorrection.Enabled = false
Blur.Enabled = false
end
end)
UnderwaterEffects.rbxl (33.3 KB)