Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to I make my knife point at the place I click?

I have been trying to make a knife I can throw and I have tried a lot of different things but it won't work. Every time the knife is thrown it is facing upwards and not to the area I clicked (it does move positions based on where I click but that's it).

local KnifeEvent = game.ReplicatedStorage.KnifeThrow
local knifeFolder = game.Workspace.Knifes

local range = 3000

KnifeEvent.OnServerEvent:Connect(function(player, mousePos, origin, originPos, pointer)
	--local direction = (mousePos - originPos).Unit * range
	
	--local result = workspace:Raycast(originPos, direction)

	
	local direction = (mousePos - originPos)
	
	local target = mousePos
	
	
	local knifeClone = origin:Clone()
	knifeClone.Anchored = true
	knifeClone.CanCollide = false
	knifeClone:ClearAllChildren()
	knifeClone.Parent = game.Workspace
	knifeClone.Name = (player.Name.. "Knife")
	
	
	local pointerClone = pointer:Clone()
	pointer.Anchored = false
	pointerClone.CanCollide = false
	pointerClone:ClearAllChildren()
	pointerClone.Parent = game.Workspace
	pointerClone.Name = (player.Name.. "pointer")
	
	local weld = Instance.new("Weld")
	weld.Part0 = knifeClone
	weld.Part1 = pointerClone
	weld.Parent = pointerClone
	
	
	
	local pointerPos = pointerClone.Position
	
	local direction = pointer.CFrame.LookVector*range
	
	local ray = Ray.new(pointerPos, direction)
	
	
	

	print("KnifeCloneMade")
	
	local part = workspace:FindPartOnRay(ray, pointerClone)
	print(part)
end)

Please give me any advise you can give.

1 comment

0

please include the script that throws the knife, I don't see anything here involved with motion.

1 answer

It is because you are referencing direction two times, that means that you are overwriting the direction and using the default CFrame of the part.

This discussion is preserved as it was. New answers, comments, and votes are closed.