How to summon instance in front of character and get it's look vector

As the title suggests, I am trying to clone an instance and make it face the mouse position and get it’s look vector
The cloning of instance and getting the mouse position is good, it can also shoot. However I can go as far as cloning it at the humanoid root part and I don’t have any idea how to make it spawn in front instead
I tried looking around the Devforum but got none so far. I’ve also tried multiplying the HRP’s CFrame with a new CFrame:

local cf = CFrame.new(hrp.CFrame --[[However since this part needs to be a Vector3, it messes up]] * CFrame.new(0,0,5), mouseCF.Position)
local newPos = cf.LookVector * 10000

however, it shows errors.
Here’s a part of the code that is related to the cloning and positioning of the instance

local hrp = plr.Character:WaitForChild("HumanoidRootPart")
local cf = CFrame.new(hrp.Position, mouseCF.Position)
local newPos = cf.LookVector * 10000
local bone = game.ReplicatedStorage.Attacks.Bone:Clone()
bone.Parent = workspace

bone.CFrame = cf

CFrame.Position is a Vector3 property of a CFrame, so you could set the new CFrame using that.

local cf = CFrame.new(hrp.CFrame.Position, mouseCF.Position)

No idea what you’re trying to achieve by multiplying that with CFrame.new(0,0,5) though.

As for shifting the position, you’re only multiplying the look vector of the part by a factor without taking into account the actual position. Think of vectors as arrows centered at the origin.

haha sorry, i totally forgot about that

i was using the cframe to determine if the instance would clone in front or back
as for the look vector, it’s not actually necessary to get where the actual position would be since the instance is a projectile which will be get rid of anyways :stuck_out_tongue:

Here’s the whole code if you’re wondering what the instance is supposed to do

local re = game.ReplicatedStorage.Events:WaitForChild("BoneSpawn")
local plrsOnCooldown = {}
local ts = game:GetService("TweenService")


re.OnServerEvent:Connect(function(plr, mouseCF)
	if plrsOnCooldown[plr] then 
		return 
	end
	plrsOnCooldown[plr] = true
	
	local hrp = plr.Character:WaitForChild("HumanoidRootPart")
	local cf = CFrame.new((hrp.CFrame * CFrame.new(0,0,-5)).Position, mouseCF.Position)
	local newPos = cf.LookVector * 10000
	local bone = game.ReplicatedStorage.Attacks.Bone:Clone()
	bone.Parent = workspace

	bone.CFrame = cf
	wait()
	local pre = ts:Create(bone, TweenInfo.new(0.8, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Orientation = bone.Orientation + Vector3.new(0, 360, 0)})
	pre:Play()
	wait(0.8)

	local ti = TweenInfo.new(3.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.In)
	local tween = ts:Create(bone, ti, {Position = newPos})
	
	tween:Play()

	tween.Completed:Connect(function()
		bone:Destroy()
	end)

	bone.Touched:Connect(function(hit)
		if hit.Parent.Name ~= plr.Character.Name then
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid:TakeDamage(10)
				if hit.Parent:FindFirstChild("DodgeAble") == nil then
					bone:Destroy()
				else
					return
				end
			end
		end
	end)

	bone.Parent = workspace

	wait(0.2)

	plrsOnCooldown[plr] = nil
end)

Edit: I figured out i could’ve just done this :man_facepalming:

local cf = CFrame.new((hrp.CFrame * CFrame.new(0,0,-5)).Position, mouseCF.Position)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.