local Enumeration = Enum
local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")
local RunService = Game:GetService("RunService")
local function OnHeartbeat()
for _, Player in ipairs(Players:GetPlayers()) do
local Character = Player.Character
if not Character then continue end
local Head = Character:FindFirstChild("Head")
if not Head then continue end
local Size = Character:GetExtentsSize()
local Parameters = RaycastParams.new()
Parameters.FilterDescendantsInstances = {Character}
local Result = Workspace:Raycast(Head.Position, Head.CFrame.UpVector * -Size.Y, Parameters)
if not Result then continue end
if Result.Instance.Name ~= "Terrain" then continue end
if Result.Material ~= Enumeration.Material.Water then continue end
--Do something if terrain material is water.
end
end
RunService.Heartbeat:Connect(OnHeartbeat)