Hey guys I’ve been trying to write a code that will detect if the player is looking at water when their player state is swimming, and that means the character needs to be blacklisted / ignored to scan for it. The raycast is running and detects water when the player is underneath it, however it will return nil if the player is above water (presumably because the ray hits the blacklisted objects in it). I was just wondering if items that get blacklisted are just instant stop collisions for raycast that cause it to return nil or there was a problem with the way the parameters are set.
local Player = game.Players.LocalPlayer
print(Player.Character)
local Character = Player.Character
Character:WaitForChild(“Humanoid”).StateChanged:Connect(function(oldState, newState)
local Humanoid = Character.Humanoid
if newState == Enum.HumanoidStateType.Swimming then
local camera = game.Workspace.CurrentCamera
while Humanoid:GetState() == Enum.HumanoidStateType.Swimming do
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(camera.CFrame.Position, Character.Head.Position - camera.CFrame.Position, raycastParams)
print(raycastResult)
wait(0.05)
end
end
end)
To reiterate, it seems that if the ray hits the player (that has been blacklisted), it will always return nil. Is there a way for it to simply ignore these blacklisted objects instead of returning nil when colliding?