Knife throw rotation [SOLVED]

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve the knife to look in the direction my character is looking

  2. What is the issue? Include screenshots / videos if possible!
    No issues I just don’t know how to make the rotation correct

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

knifeClone.CFrame = CFrame.Angles(0,Character.PrimaryPart.Rotation.Y - Character.PrimaryPart.Rotation.Y % 90,Character.PrimaryPart.Rotation.Z)

Tried this script ↑ ↑ Didn’t work. Thoughts?

knifeClone.CFrame *= CFrame.Angles(math.pi/20,0,0) -- not sure which axys to set, just test it

make sure you use something to loop this

How much times do I loop it? Filling up 29 chars

robloxapp-20220502-1628196.wmv (3.1 MB)
Just tried you’r code didnt work

knifeClone.CFrame = Character.PrimaryPart.CFrame.Rotation

and if you want to position the knife

local position = Vector3.new(69, 420, 69)
knifeClone.CFrame = Character.PrimaryPart.CFrame.Rotation + position

robloxapp-20220502-1642515.wmv (560.1 KB)
It still doesn’t work :frowning:

use run service
or while the sword exists

Okay let me try both of those and I will tell you which one works!

Didn’t work with both. It just did a weird rotation and went the whole opposite way

maybe we should use pivot if the knife is not rotated correctly

https://developer.roblox.com/en-us/resources/studio/Pivot-Tools

knifeClone:PivotTo(Character.PrimaryPart.CFrame.Rotation)

you will need to edit the knifes pivot so its facing the correct way

Nope still didn’t work :frowning:

Could you use LookVector, this mean the forward direction of a CFrame orientation.
https://developer.roblox.com/en-us/api-reference/datatype/CFrame

there is only 2 reasons i can think that its not working

  1. you never rotated the pivot

  2. when your updating the knifes position your also changing rotation

how are you making the knife move

Share the full script please (or even just the main part that handles the tools movement) so we can see what you need to do so it works.

local knifeClone = workspace.Knife
while task.wait() do
	knifeClone.CFrame *= CFrame.Angles(math.rad(-5),0,0)
end

Sure 1 second I will do that right now.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
local ServerStorage = game:GetService('ServerStorage')
local TweenService = game:GetService('TweenService')
local Debris = game:GetService('Debris')
local Damage = 6

local function Detect(Character,plr)
	local Connection 
	local knifeClone = script.Knife:Clone()
	knifeClone.Parent = workspace
	local Hitbox = knifeClone
	knifeClone.CFrame = CFrame.Angles(0,Character.PrimaryPart.Rotation.Y - Character.PrimaryPart.Rotation.Y % 90,Character.PrimaryPart.Rotation.Z)
	
	knifeClone.Position = Character.PrimaryPart.Position
	
	local bv = Instance.new("BodyVelocity")
	bv.Parent = knifeClone
	bv.MaxForce = Vector3.new(80000,80000,80000)
	bv.Velocity = Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 250
	Connection = Hitbox.Touched:Connect(function(hitted)
		if hitted.Parent and not hitted:IsDescendantOf(Character) and hitted.Parent:IsA("Model") then
			if hitted.Parent:FindFirstChild("Humanoid")  then
				if hitted.Parent:FindFirstChild("Humanoid").Health > 0 then
					knifeClone:Destroy()
					local sound = script.Hit:Clone()
					sound.Parent = hitted.Parent.Head
					sound:Play()
					Debris:AddItem(sound,1)
					local Enemy = hitted.Parent
					Enemy.Humanoid:TakeDamage(Damage)
					Enemy.Humanoid:LoadAnimation(script.Hurt):Play()
					Connection:Disconnect()
					Hitbox:Destroy()
					local B = Instance.new("BodyVelocity")
					B.Parent = Enemy.HumanoidRootPart
					B.MaxForce = Vector3.new(80000, 80000, 80000)
					B.Velocity = Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 2
					Debris:AddItem(B,0.25)
					local object = Instance.new("ObjectValue")
					object.Name = "Creator"
					object.Value = plr
					object.Parent = Enemy.PrimaryPart
					if Enemy:FindFirstChild("DamageIndicatorGui") then
						Enemy:FindFirstChild("DamageIndicatorGui").DamageIndicatorText.Damage.Value += Damage
					else
						local DamageIndicatorGui = game.ServerStorage.DamageIndicatorGui:Clone()
						DamageIndicatorGui.Parent = Enemy
						DamageIndicatorGui.DamageIndicatorText.Damage.Value = Damage 
					end
				end
			end
		end
	end)
end

ReplicatedStorage.Remotes.KnifeThrow.OnServerEvent:Connect(function(plr)
	if plr.StandName.Value == "TheWorld" then
		local character = plr.Character
		if not character.PrimaryPart.Anchored == true and plr.Backpack.UsingMove.Value == false then
			plr.Backpack.UsingMove.Value = true
			for i, track in pairs(character.Humanoid.Animator:GetPlayingAnimationTracks()) do
				if track then
					track:Stop()
				end
			end
			local anim = character.Humanoid.Animator:LoadAnimation(script.KnifeThrow)
			anim:Play()
			local sound = script.Throw:Clone()
			sound.Parent = character.Head
			sound:Play()
			wait(1)
			Detect(character,plr)	
			wait(1)		
			sound:Destroy()
			plr.Backpack.UsingMove.Value = false
		end
	end
end)

And yes this is a jojo game that I’m making

1 Like

I believe this is your code that handles the rotation. There doesn’t seem to be a loop so it will only do it once.

1 Like

What type of loop should I add then? p.s sorry for the late reply

Oh and also it doesn’t do it right.

1 Like