Why is this not blowing the player back?

Alright, First post. So I am working on a ability for a MHA game, this ability is stronger than a normal punch but also should blow your opponent back. Everything has been working perfectly other than the blowing them back part.

script.Parent.Touched:Connect(function(hit)
		local plrname = script.Parent.Parent.Name
	local char = hit.Parent
	local hum = char:FindFirstChild("Humanoid")
	if hum and char.Name ~= script.Parent.Parent.Name then
		hum.Health = hum.Health - script.Dmg.Value
		if char:FindFirstChild("AI") then
			if hum.Health <= char.AI.KillHP.Value and char:FindFirstChild("PlrWhoKilled") == nil then
			local Va = Instance.new("StringValue")
			Va.Value = plrname
			Va.Name = "PlrWhoKilled"
			Va.Parent = char
			end
			end
		local y = Instance.new("BodyVelocity")
y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
y.Velocity = script.Parent.Parent.HumanoidRootPart.CFrame.lookVector * 100
y.Parent = hit.Parent.UpperTorso
game.Debris:AddItem(y,1)
		local yolo = game.ServerStorage.Meshes.V1:Clone()
		yolo.Size = Vector3.new(1,1,0.05)
		yolo.BrickColor = BrickColor.new("Institutional white")
		yolo.CanCollide = false
		yolo.Anchored = true
		yolo.Material = "Neon"
		yolo.Transparency = 0.6
		game.Debris:AddItem(yolo, 2)
		yolo.CFrame = script.Parent.Parent.Head.CFrame * CFrame.new(0,0,0) *CFrame.Angles(math.rad(0),0,0)
			local Vaa = script.Wave
			Vaa.Parent = yolo
			yolo.Parent = game.Workspace
			Vaa.Disabled = false
			script.Disabled = true
		wait(0.5)
	end
end)

But then the issue appears and it just simply does not work, no errors or anything. I looked in the explorer it does put the velocity in the players Torso its just it does not move them. Could it be because they are dummys / rigs and not players?
Hey if I typed my code in the wrong format please tell me as I forgot how exactly I was suppose to put it.

2 Likes

You can do ```lua before your code (with a line break before starting code) and ``` after it to format it like this:

local something = whatever
2 Likes

Thank you I just updated the post and it should be in the right format now.

1 Like

Would it be okay for you to post your explorer, showing where the script/localscript is located?

It seems that some of your code relies on the hierarchy of objects.

Does the code run at all?

I’m asking because there’s an extra end at the end, maybe there’s a statement not being completed at the begginning.

My bad when I was typing it I forgot to put the On touched as im new to dev forum posting. Let me add it back.

Yeah I will update it in just a minute.

Oh, then I see the problem.

Add the extra end for

if hum.Health <= char.AI.KillHP.Value and char:FindFirstChild("PlrWhoKilled") == nil then

and get rid of the one at the bottom.

Your code should be looking like this now

script.Parent.Touched:Connect(function(hit)
		local plrname = script.Parent.Parent.Name
	local char = hit.Parent
	local hum = char:FindFirstChild("Humanoid")
	if hum and char.Name ~= script.Parent.Parent.Name then
		hum.Health = hum.Health - script.Dmg.Value
		if char:FindFirstChild("AI") then
			if hum.Health <= char.AI.KillHP.Value and char:FindFirstChild("PlrWhoKilled") == nil then
			local Va = Instance.new("StringValue")
			Va.Value = plrname
			Va.Name = "PlrWhoKilled"
			Va.Parent = char
			end
			end
            end
		local y = Instance.new("BodyVelocity")
y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
y.Velocity = script.Parent.Parent.HumanoidRootPart.CFrame.lookVector * 100
y.Parent = hit.Parent.UpperTorso
game.Debris:AddItem(y,1)
		local yolo = game.ServerStorage.Meshes.V1:Clone()
		yolo.Size = Vector3.new(1,1,0.05)
		yolo.BrickColor = BrickColor.new("Institutional white")
		yolo.CanCollide = false
		yolo.Anchored = true
		yolo.Material = "Neon"
		yolo.Transparency = 0.6
		game.Debris:AddItem(yolo, 2)
		yolo.CFrame = script.Parent.Parent.Head.CFrame * CFrame.new(0,0,0) *CFrame.Angles(math.rad(0),0,0)
			local Vaa = script.Wave
			Vaa.Parent = yolo
			yolo.Parent = game.Workspace
			Vaa.Disabled = false
			script.Disabled = true
		wait(0.5)
end)

Plus%20Ultra_%20Battle%20-%20Roblox%20Studio%204_14_2019%2011_13_55%20AM%20(2)
This is before changing its parent to the players right hand. DmgScript is the script I provided above. Please remember everything but the knock back works. And if you want to see after its been parented then just ask :stuck_out_tongue:

I just looked and that end at the bottom, it was the end for

if hum and char.Name ~= script.Parent.Parent.Name then

That if statement made it so you did not use the move on yourself or something that’s not living. So if we moved the end and the player punches a wall then its going to send the wall flying. This is why I choose to put it at the bottom so the moving ect only happen on a NPC or player.

Hm.

Maybe math.huge is just bugging? Or maybe the script isn’t picking up the humanoidRootPart and isn’t letting you know? Try printing the rootpart with the lookVector and manually changing the math.huge to just large numbers.

Edit: Maybe also try putting script.Parent.Parent.HumanoidRootPart.CFrame.lookVector * 100 in parentheses

So I just tested again and I was messing with it and the dummy (Hes standing still and is made from the animation plugin) im testing it. When I hit him he stays still and I can see the velocity in his body. The thing is its saying his HumanoidRootPart is anchored, is this normal? Next, the moment I unanchor his rootpart he blows back.

Oh, lol!

BodyVelocity only works on unanchored objects (since it only forcefully changes velocity and not position/CFrame). Also that means anything welded to the anchored object can’t move either.

So is it normal for the humanoidrootpart to be anchored? I’m guessing not.

I mean if you wanted the HumanoidRootPart to be anchored, yes.

I’m pretty sure all dummies inserted into the workplace are defaulted to be anchored incase you wanted to do animation stuff.

Defaulty, player’s characters in game will not have their HumanoidRootPart to be anchored.

1 Like

And just un anchored it and tested, works perfectly. I feel like a big idiot lol. Thanks.

Dang you solved 2 issues for me at once, I was working on a npc follow script and it was on the same dummy

1 Like