How can I get VectorForce to work?

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

  1. What do you want to achieve?
    I’m trying to make a weapon that will knock players back when it touches them using Roblox’s VectorForce.

  2. What is the issue?
    The player is not being knocked back, yet they are being touched.

  3. What solutions have you tried so far?
    I have looked through various other posts and the Roblox Documentation, but could not figure out how to correctly use VectorForces.

local tool = script.Parent
local blade = tool.Handle.Sword_Part

local debounce = false

local function touched(hit)
	if not debounce then
		debounce = true
		if hit.Parent:FindFirstChild("Humanoid") then
			print(hit)
			local humanoid = hit.Parent.Humanoid
			local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")

			if humanoid and humanoidRootPart then
				local attachment = Instance.new("Attachment", humanoidRootPart)
				local force = Instance.new("VectorForce", humanoidRootPart)
				force.Attachment0 = attachment
				force.Force = Vector3.new(0,0,1000)

				wait(1)
				force:Remove()
				attachment:Remove()
			end
		end
		debounce = false
	end
end

blade.Touched:Connect(touched)

In your command lines;

local attachment = Instance.new("Attachment", humanoidRootPart)
				local force = Instance.new("VectorForce", humanoidRootPart)
				force.Attachment0 = attachment
				force.Force = Vector3.new(0,0,1000)

I’m not sure if the 0 in force.Attachment0 was intentional.
You then call upon VectorForce in the Humanoid Rootpart, which is not necessary. You only need to apply it to HumanoidRootPart.Velocity.


You can implement it in many ways, as long as it just comes down to this.

local player = script.Parent
local rootpart = player:WaitForChild("HumanoidRootPart")

	local function touched(hit)
	if ... then --input all the necessities to act out the knockback
		rootpart.Velocity = Vector3.new(0, 0, 0) --desired direction and intensity of knockback
	end
end

blade.Touched:Connect(touched)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.