How to boost a player backwards?

Hello! I am trying to boost players backwards when they touch me, the problem is it turns the velocity into 0,0,0 even though when print the same thing of my own humanoid it prints fine!
why does my code return velocity as 0,0,0?


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= script.Parent.Parent and hit.Parent.HumanoidRootPart:findFirstChild("BOOSTAWAY") == nil then
		print("BOOSTING AWAY")
		hit.Parent:FindFirstChild("Humanoid").Sit = true
		local boost = Instance.new("BodyVelocity",hit.Parent.HumanoidRootPart)
		boost.Name = "BOOSTAWAY"
		print(hit.Parent.HumanoidRootPart.CFrame.LookVector)
		local fling = Vector3.new((hit.Parent.HumanoidRootPart.CFrame.LookVector + Vector3.new(0,2,0)) * Vector3.new(100,100,100))
		print(fling)
		boost.Velocity = fling
		wait(.5)
		boost:Destroy()
	end
end)
1 Like

Sorry, by velocity do you mean this statement?

Also, I think you should be wary that the wait statement here won’t work because of how .Touched events work as they can trigger multiple times.

To prevent the Touched event from triggering multiple times we can use a debounce as follows like in this article. It even has an example for button pressed which shows the error with putting just wait (0.5) in a touched statement. This might be what is causing the problem as well.

yes the

local fling = Vector3.new((hit.Parent.HumanoidRootPart.CFrame.LookVector + Vector3.new(0,2,0)) * Vector3.new(100,100,100))
		print(fling)

also if u read above it checks and makes sure it doesnt already have a booster in it!

Hmm, well then why are you creating a new vector 3 for an already created vector 3?

I believe because of this invalid parameter it is creating an empty vector 3 value instead of what you want.

Try this which removes the unnecessary vector3.new from:

Vector3.new((hit.Parent.HumanoidRootPart.CFrame.LookVector + Vector3.new(0,2,0)) 

To this, also try splittting it up into variables. It’s really hard to read that really long line.

local humanoidLookVector = hit.Parent.HumanoidRootPart.CFrame.LookVector
local magnitude = 100
local fling = (humanoidLookVector + Vector3.new(0,2,0) ) * magnitude
2 Likes

Works! i deleted the magnitude part and did Vector.new(-100,100,-100) and it works! Thank you!