Vector3 expected, got number

Greetings Developers,

I am currently working on creating a gun engine and I am encountering an issue with my script that creates the bullet on the Server Side.

I am attempting to modify the CFrame of the bullet to have the bullet “travel” in the correct direction, however the variable I have passed through is being expected as a Vector3 when it shouldn’t be. Does anyone know how to fix this?

Thank you!

Code:

hit.OnServerEvent:Connect(function(distance, bulletOrigin, intersection, result)
	print("Fired!")
	print(bulletOrigin)
	print(distance)
	print(intersection)
	print(result)
	local newBullet = Bullet:Clone()
	newBullet.Size = Vector3.new(0.1, 0.1, distance)
	newBullet.CFrame = CFrame.new(bulletOrigin, intersection)*CFrame.new(0, 0, -distance/2)
	newBullet.Parent = Workspace

Console Error:

  13:14:09.660  Players.Anaro_Ryker.Backpack.Gun Template.WeaponFire:22: invalid argument #1 to 'new' (Vector3 expected, got number)  -  Server - WeaponFire:22

It could be that the first parameter of a remote event is the player who sent it. Try this:

hit.OnServerEvent:Connect(function(player, distance, bulletOrigin, intersection, result)
	print("Fired!")
	print(bulletOrigin)
	print(distance)
	print(intersection)
	print(result)
	local newBullet = Bullet:Clone()
	newBullet.Size = Vector3.new(0.1, 0.1, distance)
	newBullet.CFrame = CFrame.new(bulletOrigin, intersection)*CFrame.new(0, 0, -distance/2)
	newBullet.Parent = Workspace

Savior!

That’s fixed it.

Thank you for helping!

1 Like