#raycast doesn t work

4 messages · Page 1 of 1 (latest)

rancid current
#

The script you provided appears to have a few issues. Let's go through them and make the necessary fixes:

The line defaultRout(workspace.destination) seems to be calling a function defaultRout with an argument workspace.destination. If this function exists and is defined elsewhere in your code, you can keep this line. Otherwise, you can remove it.

The line local rayCastResult = workspace:Raycast(body.Position, (workspace.destination.Position - body.Position).Unit * 1000, raycastParams) is responsible for performing the Raycast. However, it seems that workspace.destination might not be defined correctly. Make sure workspace.destination refers to the destination you want to cast the ray towards. If it's not defined or incorrect, replace it with the correct destination position.

The line if rayCastResult.Instance:IsA("Model") and rayCastResult.Instance:FindFirstChildOfClass("Humanoid") then checks if the Raycast result is a model with a Humanoid as its child. If that's the case, it prints the name of the instance. This part looks fine, but make sure it aligns with your intended functionality.

Here's the modified script with the suggested fixes:

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.FilterDescendantsInstances = {body}
while wait() do
    local destination = Vector3.new(0, 0, 0) -- Replace with the desired destination position
    local direction = (destination - body.Position).Unit
    local rayCastResult = workspace:Raycast(body.Position, direction * 1000, raycastParams)
    if rayCastResult then
        if rayCastResult.Instance:IsA("Model") and rayCastResult.Instance:FindFirstChildOfClass("Humanoid") then
            print(rayCastResult.Instance.Name)
        end
    end    
end```

Remember to replace Vector3.new(0, 0, 0) with the actual destination position you want to cast the ray towards.
rancid current
#

its from chat gpt

cinder vine
#

did you get your role with chatgpt