Im trying to make it so that when the player’s head touches water, they start losing health and a blurry effect appears on their screen and it works but whenever the player exits the water the effect stays
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local health = humanoid.Health
local function enableFX(inWater)
if inWater == true then
game:GetService('Lighting').WATER_BLUR.Enabled = true
game:GetService('Lighting').WATER_COLOR.Enabled = true
end
if inWater == false then
game:GetService('Lighting').WATER_BLUR.Enabled = false
game:GetService('Lighting').WATER_COLOR.Enabled = false
end
end
while wait() do
local head = character:FindFirstChild("Head")
local min = head.Position - (4 * head.Size)
local max = head.Position + (4 * head.Size)
local region = Region3.new(min,max):ExpandToGrid(4)
local material = workspace.Terrain:ReadVoxels(region,4)[1][1][1]
if material == Enum.Material.Water then
enableFX(true)
wait(20)
repeat
wait(1)
humanoid.Health = humanoid.Health -5
until
humanoid.Health == 0 or material ~= Enum.Material.Water
else
enableFX(false)
end
end