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

Knock-back part not knock backing enemies?

So I made a wall that knocks back players this Is the script:

(BTW I DIDN'T ADD BODY VELOCITY BECAUSE ITS DEPCERATED)

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:WaitForChild("Humanoid")
	if humanoid then
		local KnockBack = Instance.new("VectorForce")
		
		KnockBack.Parent = humanoid.Parent
		KnockBack.Attachment0 = humanoid.Torso
		KnockBack.Force = Vector3.new(-1000,0,0)
	end
end)

1 answer

Hm, maybe try switching out :WaitForChild("Humanoid") for :FindFirstChild("Humanoid")?

Also, Attachment0 is for an attachment. Here, try this.

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		if not humanoid.Parent.Torso:FindFirstChild("VectorForce") then
			local KnockBack = Instance.new("VectorForce")
			local Attachment = Instance.new("Attachment")

			Attachment.Parent = humanoid.Parent.Torso
			KnockBack.Parent = humanoid.Parent.Torso
			KnockBack.ApplyAtCenterOfMass = true
			KnockBack.Attachment0 = Attachment
			KnockBack.Force = Vector3.new(0,3000,6000)
			humanoid.Jump = true
			game:GetService("Debris"):AddItem(KnockBack,0.5)
			game:GetService("Debris"):AddItem(Attachment,0.5)
		end
	end
end)

1 comment

0

Thanks!

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