Script:70: invalid argument #1 to 'new' (Vector3 expected, got CFrame)

You can get the position of the handle.

image
I tested it aswell using CFrame instead of Vector3 because I wasn’t sure and it seems to error like in your situation.

You could try getting the position of the CFrame you are creating by doing

bodyvelocity.velocity = (CFrame.new(HammerCopy.CFrame,HumanRoot.CFrame).lookVector * 100).p
1 Like

You are passing the wrong arguments into CFrame.new() on the 3rd line. You need to pass 2 Vector3s not 2 CFrames.

This should work

local bodyvelocity = Instance.new("BodyVelocity")
		bodyvelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
		bodyvelocity.velocity = CFrame.new(HammerCopy.Position,HumanRoot.Position).lookVector * 100	
		bodyvelocity.Parent = HammerCopy	

Oh it should stay as cframe.new instead vector3.new? But bodyvelocity.velocity is a vector3 value isn’t it?

Well, no. Since you are getting the LookVector of the CFrame, and the LookVector is a Vector3, you don’t need to change anything.

Alright I did that and a new error has come up: “Script:70: attempt to index nil with ‘Position’”

Are you sure the humanroot and hammercopy are Parts or baseparts? if so then it should have an assigned vector3 position

This is probably because either HammerCopy is nil or HumanRoot is nil.

The hammercopy is a tool so I got the position of the handle.

1 Like

then do hammercopy.Handle.Position

So if the hammercopy is nil, what can I do to fix it?

Check if HammerCopy exists (if HammerCopy then) before creating the bodyvelocity.

Alright just to give some context for what I’m trying to do, I’m creating thor’s hammer with the ability to call it back from the direction it was thrown in.

This is the local script:

local HammerEvent = script.Parent:WaitForChild("HammerEvent")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local OriginalHammer = game.StarterPack["Thor's Hammer"]
local CallbackEvent = script.Parent:WaitForChild("CallbackEvent")



Tool.Equipped:Connect(function(Mouse)		
Mouse.Button1Down:Connect(function()
	local Location = Mouse.Hit.p
	HammerEvent:FireServer(Location)
	end)
	Mouse.Button2Down:Connect(function()
		CallbackEvent:FireServer()
	end)
end)

And the server script where all the stuff gets done:

local HammerEvent = script.Parent:WaitForChild("HammerEvent")
local Handle = script.Parent:WaitForChild("Handle")
local ServerStorage = game:GetService("ServerStorage")
local Hammer = ServerStorage:WaitForChild("Hammer")
local RunService = game:GetService("RunService")
local NotEnabledTime = 2
local EnableTime = 0
local Enable = true
local Thrown = false
local CallBackEvent = script.Parent:WaitForChild("CallbackEvent")

local function OnHammerFired(player, Location)
--print(player, Location)	
	if Enable == true then
		if Thrown == false then
			Thrown = true
		end
     Enable = false	
		
	local ray = Ray.new(Handle.CFrame.p, (Location - Handle.CFrame.p).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
	
	local distance = (Handle.CFrame.p - position).magnitude
	
	Handle.Transparency = 1
	
	local CopieHammer = Hammer:Clone()
	CopieHammer.CanCollide = false
	CopieHammer.CFrame = CFrame.new(Handle.CFrame.p, position) * CFrame.Angles(math.rad(-90), 0, 0)
	CopieHammer.Parent = game.Workspace
	
    local bodyvelocity = Instance.new("BodyVelocity")
    bodyvelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    bodyvelocity.velocity = CFrame.new(Handle.CFrame.p, Location).lookVector * 100	
	bodyvelocity.Parent = CopieHammer	
		
	spawn(function()	
	CopieHammer.Touched:Connect(function(hit)
	if hit.Parent.Name ~= player.Name then			
	local humanoid = hit.Parent:FindFirstChild("Humanoid")		
	if humanoid then		
		humanoid:TakeDamage(30)	
		CopieHammer:Destroy()		
		wait(2)			
				
	end			
	end			
	end)		
	end)
	wait(3)			
	CopieHammer:Destroy()							
	Enable = true
end
end

local function OnHammerCall(Player)
	local Character = Player.Character
	local HumanRoot = Character:WaitForChild("HumanoidRootPart",15)
	if Thrown == true then
		Thrown = false
		local HammerCopy = workspace:WaitForChild("Hammer")
		local Handle2 = HammerCopy:FindFirstChild("Handle")
		local function GetCFrame()
			return HammerCopy:FindFirstChild("Handle").Vector3
		end
		
		
		local bodyvelocity = Instance.new("BodyVelocity")
		bodyvelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
		bodyvelocity.velocity = CFrame.new(HammerCopy.Position,HumanRoot.Position).lookVector * 100	
		bodyvelocity.Parent = HammerCopy	
		
		wait(3)
		HammerCopy:Destroy()
		
		Handle.Transparency = 0
		Enable = true
	end
end

HammerEvent.OnServerEvent:Connect(OnHammerFired)
CallBackEvent.OnServerEvent:Connect(OnHammerCall)

If the hammercopy is nil, how do I reference its position and direction that it was thrown in the throw function to be used in the callback function? Or do I have to fire some data from the first server function and back to the client then back to the server? Or am I doing it completely wrong because I’m creating this off the top of my head. ( The throw works btw, only the callback is wonky)

1 Like

That solves that specific error, but it still doesn’t work lmao.

1 Like

Ah. Well, if HammerCopy was nil then you would get warning. This probably means that either

  1. HammerCopy was deleted or
  2. HumanRoot is nil
1 Like

Well there are no more errors in the output now and the hammer still isn’t flying back to me, so I’ve probably taken the wrong approach. Do you have any ideas as to how I can get around this?

Are you sure that the hammer isn’t anchored?

Yeah i’ve double checked that the hammer isn’t anchored.

Try closing studio and then opening the place again. If that still doesn’t work, use the built-in debugger.