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)
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.