while true do
local R = RaycastParams.new()
R.FilterType = Enum.RaycastFilterType.Whitelist
R.FilterDescendantsInstances = {Enum.Material.Water}
local Start = script.Parent.Position
local End = script.Parent.Position - Vector3.new(0,10,0)
local Size = Vector3.new(3,3,3)
local BlockCast = workspace:Blockcast(Start,Size,End,R)
print(BlockCast)
wait(0.5)
end
This is supposed to BlockCast to find terrain water. It’s inside a Dummy’s HumanoidRootPart, and it is a local script. I rolled the Dummy into water, and it nothing printed. (This my first time using BlockCast so sorry if these are silly questions)
I’d assume the script isn’t executing at all is why the print doesn’t show anything. Did you try changing to a server script? local scripts don’t run on the server so unless you are only creating the dummy on the client it would need a server script to run.
You need to put in the physical Instances that you wish to filter not just an enumerated value. If there are parts in the workspace that are water you would add those or if you put all your water parts into a folder you could reference the folder as the Instance.
while true do
local R = RaycastParams.new()
R.FilterType = Enum.RaycastFilterType.Whitelist
R.FilterDescendantsInstances = {game:GetService(“Workspace”).Terrain}
local Start = script.Parent.Position
local End = script.Parent.Position - Vector3.new(0, 10, 0)
local Size = Vector3.new(10, 10, 10)
local BlockCast = workspace:BlockCast(Start, End, Size, R)
if BlockCast then
print(“Water detected”)
else
print(“No water detected”)
end
wait(0.5)
end
I’ve never worked with this before, so I’ll need to look more into it. Also, I have an error with the BlockCast variable. I don’t know which variable, but it is “Unable to cast Vector3 to CoordinateFrame”
the start variable must a cframe and the direction must be CFrame.LookVector? idk probably I can’t explain it correctly btw you can try my code
--!strict
local RunService = game:GetService("RunService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local rootPart = humanoid.RootPart :: BasePart
if not rootPart then
humanoid:GetPropertyChangedSignal("RootPart"):Wait()
rootPart = humanoid.RootPart :: BasePart
end
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {character}
RunService.Stepped:Connect(function()
local raycastResult = workspace:Blockcast(rootPart.CFrame, rootPart.Size, rootPart.CFrame.LookVector * 5, raycastParams)
if raycastResult then
print(raycastResult.Material)
end
end)
This code can only check if the player is in front of the water
the script is located in StarterCharacterScripts inside StarterPlayer when the script load the script will clone and place inside the character so the script.Parent should return the model of the character
while true do
local R = RaycastParams.new()
R.FilterType = Enum.RaycastFilterType.Whitelist
R.FilterDescendantsInstances = {game:GetService(“Workspace”).Terrain}
local Start = script.Parent.Position
local End = script.Parent.Position - Vector3.new(0, 10, 0)
local Size = Vector3.new(10, 10, 10)
local BlockCast = workspace:BlockCast(Start, End, Size, R)
if BlockCast then
print(“Water detected”)
else
print(“No water detected”)
end
wait(0.5)
end