Hi, so im making a script in a part that detects the terrain material thing “water”
And i have no i dea how to do so, i searched up but nothing was relevant for me, if you would like to help, feel free this is the code btw
local part = script.Parent
local damageAmount = 10
local function shootRay()
local position = part.Position
local forwardVector = part.CFrame.LookVector
local ray = Ray.new(position, forwardVector * 2)
local hit, hitPosition, hitNormal = workspace:FindPartOnRay(ray)
if hit then
print("Hit something at:", hitPosition)
local terrain = workspace.Terrain
if Idk what do define here do something here == Enum.Material.Water then -- here how the hell
local character = game.Players:GetPlayerFromCharacter(hit.Parent)
if character then
local humanoid = character.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(damageAmount)
print("Player took damage in water!")
end
end
end
else
print("Ray did not hit anything.")
end
end
while wait(2) do
shootRay()
end
so at line 18 is the place where idk anymore, im casting a ray 2 studs from the look vector of the part and want to detect water but how?
this water btw
that yellow thing is the part, the script is parented into the part