Attempt to perform arithmetic on local 'Direction' value (a userdata value) help?

Hello there, so I have a problem i have after reworking my raycast weapons into using Fastcast, A great Module to use that allows you to make projectiles with raycasting, and I was reworking my weapons to use this, so most of the raycast code for it comes from the fastcast test weapon that was put in the fastcast thread that I stated in the thread above.

What happens when firing a weapon, the error given is this.
16:56:20.950 - Players.joshuasol.Backpack.AR15 RPH.Scripts.BackendScript:207: attempt to perform arithmetic on local 'Direction' (a userdata value)

(gif here to show it, mainly the output below.)
https://gyazo.com/fd5689e4636d6f41db3fe262ab0336ea

Where does this take place?

Firstly, Here’s the client script where the function fires into the server script where the fastcast ray is going to fire, and where the problem is specifically, on line 206.

What have i tried to debug the issue?
When I tried debugging the issue, I first went into the Client script where it fires to try and figure out FireDirection, as it most likely seems the same as the Direction portion in the serverside script. As I did this, i did print(FireDirection,type(CFrame.new(FireDirection))), and this is what it gives me.

-2.85255028e-05, 0.0103102932, -0.999946833 userdata

so after this and it not really giving me much, i searched a bit on the magical item known as the “internet” to figure out that just like how the error gives me, I can’t do arithmetic on a C object. Now, the only other thing I can think up of to do when the problem occurs is to figure out what .Unit and .Direction should be, but I can’t figure it out this time because it’s the first time i’ve used fastcast.

What should I do here, and if anyone can, please help provide a solution to the problem? If anyone helps, thank you.

1 Like

Could you try using print(Direction, typeof(Direction)) right before that line to see what it prints? My best guess is that Direction is a CFrame value trying to be multiplied by a number value, which is not a valid expression.

trying to print it on the server causes nothing to print for some reason.

I mean trying to print it right before that line in the client’s script.
e.g:

205 | local MyMovementSpeed = --...

206 | print(Direction, typeof(Direction))

207 | local ModifiedBulletSpeed = --...

Ok sorry, rookie mistake. It states that it’s an instance.

edit: yeah, i also expected it to be a cframe, but now with this debug it isn’t showing that, clearly.

It looks like Direction is either your character or the player, which seems like a mistake in the variable’s definition.

Try using print(Direction, Direction.ClassName) just to make sure it might be either of those things.

wow, it truly was the player.

now what do i do? lol

Well, now we have to look at where this function is being called, since Direction is a parameter to the function shoot.
Is this connected to a RemoteEvent, or anything similar?

wait, i completely forgot to state where it is in the client script, so sorry.

here is the client where it’s fired from, where i talked about it. and yes, it’s connected to a remoteEvent.

(as you see, specifically shootRemote:FireServer(FireDirection)

So are you connecting shoot to the RemoteEvent? If so, you have to add a parameter for the player that fired the event.
EDIT: Here’s an example:

local function shoot(Player, Direction)
2 Likes

alrighty, will try it out. if it works, theres a free solution for you.

edit: thank you so much! ok so i’ve gotten it to fire, now here’s where i will need to figure out the majority of fastcast within the module. If you know how fastcast works and want to continue it, feel free to. but my main problem is solved.

1 Like