Need help changing depreciated things to working things

Hello developers! I hope you are all having an amazing day. Today, there is a depreciated script that I want to turn into a new script:

local module = {}

function module.new(startPosition, startDirection)
	local maxDistance = startDirection.magnitude
	local direction = startDirection.unit
	local lastPosition = startPosition
	local distance = 0
	local ignore = {}
	
	local hit, position, normal
	
	repeat
		local ray = Ray.new(lastPosition, direction * (maxDistance - distance))
		hit, position, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
		if hit then
			if not hit.CanCollide then
				table.insert(ignore, hit)
			end
		end
		distance = (startPosition - position).magnitude
		lastPosition = position
	until distance >= maxDistance - 0.1 or (hit and hit.CanCollide)
	return hit, position, normal
end

return module

How can I make FindPartOnRayWithIgnoreList not depreciated? If you can help, please let me know. Thanks, WE!

The things it told me to do on the article didn’t make sense.

Use RaycastParams.

local params = RaycastParams.new()
params.FilterDescendantInstance = { —array of parts you want the rat to ignore. }
params.FilterType = Enum.FilterType.Blacklist —I think it’s called FilterType. This will make the ray to ignore whatever’s part’s that’s inside the table.

local result = workspace:Raycast(rayOrigin,direction,params)
if result then
    local object = result.Instance
    — do stuffs with it.
end

You can use the workspace:Raycast method. which isn’t deprecated, and is also more efficient in my opinion, for the ignore list you can create a new RaycastParams object and specify it accordingly


Also side note, I believe you meant to say deprecated not depreciated

1 Like

As I said here:

It is really confusing.

It keeps erroring whenever I paste it in.

Which article are you referring to? The API Reference that I have given should have an example to understand it properly.

Well it doesn’t work… I don’t know where to put anything in the script.

Can you show me the error? Maybe we can trace the solution.

image
What I did:

local module = {}

function module.new(startPosition, startDirection)
	local maxDistance = startDirection.magnitude
	local direction = startDirection.unit
	local lastPosition = startPosition
	local distance = 0
	local ignore = {}
	
	local hit, position, normal
	
	repeat
		local params = RaycastParams.new()
		params.FilterDescendantInstance = {}
		params.FilterType = Enum.FilterType.Blacklist --I think it’s called FilterType. This will make the ray to ignore whatever’s part’s that’s inside the table.

		local result = workspace:Raycast(rayOrigin,direction,params)
		if result then
			local object = result.Instance
			--do stuffs with it.
			end
		distance = (startPosition - position).magnitude
		lastPosition = position
	until distance >= maxDistance - 0.1 or (hit and hit.CanCollide)
	return hit, position, normal
end

return module

… just change that to a Vector3 value position where the ray will originate. Be smart, and don’t just copy and paste.

2 Likes

It seems like you’re having trouble with understanding the code. For integrating the workspace Raycast function in your code, you will have to do something like this:

   local hit, position, normal
   local raycastParams = RaycastParams.new()
   raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
   raycastParams.FilterDescendantsInstances = {} --Insert your objects you want to ignore in this table

	repeat
        local raycastResult = workspace:Raycast(lastPosition, direction * (maxDistance - distance), raycastParams) --Pass in the raycast Params in this method.

        --Raycast Result returns a raycast Result, which has different properties
       -- like raycastResult.Position, raycastResult.Instance, but first check if its not nil.
	until distance >= maxDistance - 0.1 or (hit and hit.CanCollide)

	return hit, position, normal

And like @ItzMeZeus_IGotHacked mentioned, you need to use some logic while implementing this and if there are any errors you face after that, then you can post it here.

image
And the kart is not moving:
image

I just want to say, if you are just going to copy paste all that we are giving as an example. Then sorry I am unable to help you, unless you actually use your logic because I am not here for fixing your script totally, as it won’t help you with anything.

2 Likes

I have never used WorldRoot:Raycast before.

That is the reason we have provided you with examples, so you can understand it and go on with implementing it on your own. As for that error, its just that repeat loop is probably running infinitely as there is nothing being set for the distance or hit.

1 Like

Then watch a tutorial about it, and use your logic and skills to implement into achieving your result.

2 Likes