Help fixing an error

Hello so I’ve been working on a takedown kill for an upcoming game idea and I have realized a flaw in my code :thinking:. I need to be facing a certain area for my character to look like he is actually doing the takedown. At the moment my animation looks weird because my character is not facing the right way. How could I potentially fix this?

How it looks so far so you can get a reference on how I could fix this.

https://gyazo.com/f2a810371f7738ff733d9e99797abd26

local hitbox = script.Parent
local knife = game.StarterPack:FindFirstChild("Knife")

local db = true

hitbox.Touched:Connect(function(hit)
	local char = hit.Parent
	local hum = char and char:FindFirstChild("Humanoid")
	local plr = game.Players:FindFirstChild(char.Name)
	

	if db and hum and plr then
		db = false
		local KTF = plr:WaitForChild("KTF")
		local KT = KTF:FindFirstChild("Takedown")
	 
		if KT.Value then
			KT.Value = false
			game.ReplicatedStorage.TakedownCam:FireClient(plr)
			game.ReplicatedStorage.TakedownAnimV1:FireClient(plr)
			script.Parent.Parent.Humanoid.Health = 10
		else
			print("Takedown is not available at the moment")
		end
		
		wait(1)
		db = true
	end
end) 

A script could be helpful to see :thinking:

1 Like

Oops haha forgot to add it. Fixed now.

It seems like you’ll have to assign the HumanoidRootPart’s CFrame to where the Target is currently facing, try this:

local hitbox = script.Parent
local knife = game.StarterPack:FindFirstChild("Knife")

local db = true

hitbox.Touched:Connect(function(hit)
	local char = hit.Parent
	local hum = char and char:FindFirstChild("Humanoid")
	local plr = game.Players:FindFirstChild(char.Name)
	

	if db and hum and plr then
		db = false
        char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, Target.Position)
		local KTF = plr:WaitForChild("KTF")
		local KT = KTF:FindFirstChild("Takedown")
	 
		if KT.Value then
			KT.Value = false
			game.ReplicatedStorage.TakedownCam:FireClient(plr)
			game.ReplicatedStorage.TakedownAnimV1:FireClient(plr)
			script.Parent.Parent.Humanoid.Health = 10
		else
			print("Takedown is not available at the moment")
		end
		
		wait(1)
		db = true
	end
end) 

You’ll have to reference where the Target is though

What does this line do?

Would this make the player face the way I want it to?

Pretty much, just make sure to assign what Target you’re wanting to takedown though

I don’t exactly know what Target is referenced as. I just started learning scripting about 3-4 months ago.

The Target is referenced as the Target that was used in your video:
image

Oh, so I would make a variable called “Target”?

Pretty much, I’m assuming this script is parented inside the Target Model itself?

Kind of, I have a part called “Hitbox” in the target model and the script is inside of hitbox.
image

When I run the script I get the error

" Position is not a valid member of Model “Workspace.Hanuman2000” "

Ah

You could just reference the Hitbox’s Position as this then I’d assume

local hitbox = script.Parent
local knife = game.StarterPack:FindFirstChild("Knife")

local db = true

hitbox.Touched:Connect(function(hit)
	local char = hit.Parent
	local hum = char and char:FindFirstChild("Humanoid")
	local plr = game.Players:FindFirstChild(char.Name)
	

	if db and hum and plr then
		db = false
        char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, hitbox.Position)
		local KTF = plr:WaitForChild("KTF")
		local KT = KTF:FindFirstChild("Takedown")
	 
		if KT.Value then
			KT.Value = false
			game.ReplicatedStorage.TakedownCam:FireClient(plr)
			game.ReplicatedStorage.TakedownAnimV1:FireClient(plr)
			script.Parent.Parent.Humanoid.Health = 10
		else
			print("Takedown is not available at the moment")
		end
		
		wait(1)
		db = true
	end
end)

Wouldn’t this be based on which side is the front on the part?

If so the front for me is the left side of the target

Yes…?

It really depends on where you want to position & rotate the Character to handle the takedown when the cutscene plays

I got it to work, thanks mate.