Attempt to index nil with 'Velocity' error

Hello there.

So, I have encountered an error, which is seen in the title, “Attempt to index nil with ‘Velocity’”.

Velocity is referring to the Velocity instance inside of a BodyVelocity, which is inside a tool of mine

I know how this error occurs, but I don’t know how to patch/fix it.
Pretty much, when I try to destroy the BodyVelocity before it’s used, it gives me this error.

How would I fix it?
Help is appreciated.

1 Like

Not sure, maybe its something to do with BodyVelocity being deprecated?

Would you like to review the script?

Here is the error in the output btw, not sure if it matters:

Once you destroy the body velocity, something is still trying to access it, after its been destroyed.
Without seeing any code, I can’t give you more than that, but that is what is happening

Interesting. Here is the code for the tool:

its pretty much my own way of making a boomerang

When something is deprecated, it still works, just it is recommended to not use it for new projects, as it has the potential of being removed in the future (not much of a concern with that for Roblox) but more importantly, newer and supposedly better things have replaced it.
But deprecated items still work.

So this is a server script or client script in the tool?
And is it directly under the tool instance?

This is a client sided script. Its inside of the tool instance. It isn’t in the handle of the tool.

Ok, I am making an empty tool with a simple cube handle and will paste this script in and see if I can get it to have the same error.

Oh wait, before you do that, you need to insert a module script inside of the client script.

You don’t have to name the module script anything btw.

Here is the code for the module script:

local module = {}

function module.executeinvisible ()
	script.Parent.Parent.Handle.Transparency = 1
end

function module.executevisible ()
	script.Parent.Parent.Handle.Transparency = 0
end

return module

Also, what is the thing in replicated storage in a folder, can I use just a simple 1x1x1 part for that?

Make sure the other part is longer or more wider than the handle.

Add a folder inside of ReplicatedStorage, than put the object that is longer or wider than the handle inside of it.

Then, name it “objectDetection”.

Make sure CanCollide is true for the object, and make sure it isn’t anchored. Also make sure CanTouch and CanQuery is true.

The error happens when the boomerang hits a wall, like a long part.

That is the cutest thing ever!
Hate to say, but I’m not getting the error you got.
Although I did have to disable the animaton and sound

I’ll look through the code to see if I can see anything wrong.
When is the error actually happening?

Hah! I didn’t think it was gonna be cute, but sure!

Anyway, make a wall (part) that is very long and wide inside of the workspace.

Like this for example:

Screenshot 2023-08-09 113011
Make sure CanCollide is true, and make sure that its anchored.

Now try throwing the boomerang at the wall, and you will get the error.

By cute, I mean because in testing I have a little cube, and its like im trying to throw it away, and it spins right back to me. Must love me :stuck_out_tongue:
image

Ok so I am getting the error, and looking in the touched event, and I see you doing some coroutine stuff.
Explain what you are doing when the object hits something, such as the wall?

I know, that’s why I wasn’t sure if it was because it was deprecated or not. Maybe a recent update broke it.

Lol!

So when the boomerang hits the wall, it is supposed to return to the player, thats really it.

As seen here, inside of the boomerang code:

bruh i just fixed it, i was just making the velocity nill
im dumb

O.O lol, sometimes its just that simple, huh XD
Hey, I do that so often, you wouldn’t believe. And its always AFTER I post in the forums.

Glad its working for you, its really a neat little effect.

1 Like

Lol, thank you for helping me man, I really appreciate it.

Here is the part of the code, inside of the wall touch code, that I had fixed the glitch:


					touched = true
					bodyvel:Destroy()

				-->	bodyvel = nil <--

					bodypos = Instance.new("BodyPosition",clone)
					bodypos.MaxForce = Vector3.new(100000,100000,100000)
					bodypos.P = 5500
					bodypos.D = dampening 

Once I removed the line with the arrows, everything else was pretty much heaven. No errors or anything.

1 Like