Why isn't BodyVelocity and TakeDamage working?

Hi Devforum, I’m learning to program and I’ve encountered a problem where BodyVelocity isn’t working and I don’t know why. Additionally, TakeDamage isn’t working either.

Here is a part of my script:

	local Hitbox = require(ReplicedStorage.MuchachoHitbox)
	
	
	local hitbox = Hitbox.CreateHitbox()
	hitbox.Size = Vector3.new(10.4, 13.7, 7.2)
	hitbox.CFrame = origin
	hitbox.Visualizer = false
	
	hitbox.Touched:Connect(function(hit, hum)
		hum:TakeDamage(100)
		print(hit)
		
		local HitEffect = ReplicedStorage.Assets.VFX.HitEffect:Clone()
		HitEffect.CFrame = hit.Parent.HumanoidRootPart.CFrame
		HitEffect.Parent = workspace.VFX
		HitEffect.Attachment.Crescents:Emit(3)
		HitEffect.Attachment.Debris:Emit(12)
		HitEffect.Attachment.Flash:Emit(1)
		HitEffect.Attachment.Shardes:Emit(16)
		

		local bv = Instance.new("BodyVelocity")
		bv.Parent = hit.Parent.HumanoidRootPart
		bv.MaxForce = Vector3.new(1,1,1) * math.huge
		bv.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 100
		Debirs:AddItem(bv, .1)
	end)
	
	hitbox:Start()
	
	wait(.7)
	
	hitbox:Stop()

I’m also providing a video to show the issue:

3 Likes

Is this running in a localscript or a normal script, because the only reason I think it wouldn’t work is it’s a localscript

This is working on a Module Script.

1 Like

The .Touched event only accepts one parameter: hit, not the Humanoid. The hit part will be a child of the Character. In order to get the Humanoid from the hit part you will first have to get the Character and then the Humanoid inside the character.

local Hitbox = require(ReplicedStorage.MuchachoHitbox)
	
	local hitbox = Hitbox.CreateHitbox()
	hitbox.Size = Vector3.new(10.4, 13.7, 7.2)
	hitbox.CFrame = origin
	hitbox.Visualizer = false
	
	hitbox.Touched:Connect(function(hit)
		local Humanoid: Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
		if not Humanoid then
			return
		end
		Humanoid:TakeDamage(100)
		print(hit)
		
		local HitEffect = ReplicedStorage.Assets.VFX.HitEffect:Clone()
		HitEffect.CFrame = hit.Parent.HumanoidRootPart.CFrame
		HitEffect.Parent = workspace.VFX
		HitEffect.Attachment.Crescents:Emit(3)
		HitEffect.Attachment.Debris:Emit(12)
		HitEffect.Attachment.Flash:Emit(1)
		HitEffect.Attachment.Shardes:Emit(16)
		

		local bv = Instance.new("BodyVelocity")
		bv.Parent = hit.Parent.HumanoidRootPart
		bv.MaxForce = Vector3.new(1,1,1) * math.huge
		bv.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 100
		Debirs:AddItem(bv, .1)
	end)
	
	hitbox:Start()
	
	wait(.7)
	
	hitbox:Stop()

This code should work, let me know if you need anything else.

2 Likes

The damage dealing works, but the BodyVelocity still isn’t working

1 Like

The ModuleScript doesn’t affect how anything works. Where are you requiring the script?

2 Likes

You messed up the name of the service, it’s Debris. Unless your variable is called Debirs. Can you show me where you define the variable for the Debris service?

Talking about this line:

Debirs:AddItem(bv, .1)
1 Like

Oh and where do you define the Character variable you use here:

bv.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 100
1 Like

where it says

hitbox.Touched:Connect(function(hit)
    --script
end

I’m not sure if that’s what you mean

There we get the hit variable inside the function connected to the .Touched event, but when you set the velocity of the BodyVelocity you use a variable called Character that is never defined in the script. Is this the full script? If it isn’t, I’ll have to add some things.

1 Like

Does the dummy you’re testing this on have their humanoid root part unanchored?

1 Like

No, that’s not the full script. I’ll paste it below; maybe it will help.

local Skill = {}

local ReplicedStorage = game.ReplicatedStorage
local Debirs = game:GetService("Debris")
local TweenSerice = game:GetService("TweenService")

function Skill:Start(Player, Character)

	local humanoid = Character:WaitForChild("Humanoid")

	humanoid.WalkSpeed = 0
	humanoid.JumpHeight = 0

	local animation = ReplicedStorage.Assets.Skillsets.Flame.Animations.FireFIst
	local LoadAnimation = humanoid:LoadAnimation(animation)
	LoadAnimation:Play()
	LoadAnimation:AdjustSpeed(1)

	local charge = ReplicedStorage.Assets.Skillsets.Flame.VFX.Charge:Clone()

	local weld = Instance.new("Motor6D")
	weld.Part0 = charge
	weld.Part1 = Character:WaitForChild("Left Arm")
	weld.C0 = CFrame.new(0,0.7,0)
	weld.Parent = charge
	charge.Anchored = false
	charge.Parent = workspace.VFX

	for _, v in pairs(charge:GetDescendants()) do
		if v:IsA("ParticleEmitter") then
			v.Rate = 50
			v.Enabled = true
		end
	end

	task.wait(2.6)
	for _, v in pairs(charge:GetDescendants()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = false
		end
	end
	Debirs:AddItem(charge, 1)



	local raycastPARAMS = RaycastParams.new()
	raycastPARAMS.FilterType = Enum.RaycastFilterType.Exclude
	raycastPARAMS.FilterDescendantsInstances = {Character, workspace.VFX}

	local origin = Character.HumanoidRootPart.CFrame * CFrame.new(0,2,-8)


	local Hitbox = require(ReplicedStorage.MuchachoHitbox)

	local hitbox = Hitbox.CreateHitbox()
	hitbox.Size = Vector3.new(10.4, 13.7, 7.2)
	hitbox.CFrame = origin
	hitbox.Visualizer = false

	hitbox.Touched:Connect(function(hit)
		local Humanoid: Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
		if not Humanoid then
			return
		end
		Humanoid:TakeDamage(10)
		print(hit)

		local HitEffect = ReplicedStorage.Assets.VFX.HitEffect:Clone()
		HitEffect.CFrame = hit.Parent.HumanoidRootPart.CFrame
		HitEffect.Parent = workspace.VFX
		HitEffect.Attachment.Crescents:Emit(3)
		HitEffect.Attachment.Debris:Emit(12)
		HitEffect.Attachment.Flash:Emit(1)
		HitEffect.Attachment.Shardes:Emit(16)


		local bv = Instance.new("BodyVelocity")
		bv.Parent = hit.Parent.HumanoidRootPart
		bv.MaxForce = Vector3.new(1,1,1) * math.huge
		bv.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 100
		Debirs:AddItem(bv, .1)
	end)

	hitbox:Start()

	wait(.7)

	hitbox:Stop()
	humanoid.WalkSpeed = 16
	humanoid.JumpHeight = 7.2





end

return Skill

1 Like

Do you get any errors in the console?

Yes, I checked if the dummy was unanchored, and it was.

No, I don’t have any errors in the console.

Interesting, I just tested the BodyVelocity on a Dummy and it works.

BodyVelocity is deprecated meaning it does work anymore. Just use VectorVelocity.

Deprecated does not mean it doesn’t work anymore. It means it’s not intended to be used in new projects but it still works.

Oh ok. Still i would suggest using VectorVelocity.

2 Likes

I agree, it would be a better choice but BodyVelocity should work. I don’t understand why it’s working for me and not for him when the code looks functional.