How to terminate player's velocity on touching a part

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

  1. What do you want to achieve? Keep it simple and clear!
    Make the player stop when a part is touched instead of flinging.

  2. What is the issue? Include screenshots / videos if possible!
    The player flings away and passes through parts. The player has body velocity
    This happens: robloxapp-20220725-1237146
    The BodyVelocity is inserted from the following script:

local dash = Instance.new("BodyVelocity", humrp)
	dash.P = 1250
	dash.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	dash.Velocity = humrp.CFrame.lookVector*110*Vel*0.7
	game.Debris:AddItem(dash, 0.1)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried setting the player’s velocity to 0 when the part is touched and anchoring the humanoidrootpart but it still allows the player to noclip and still ragdolls the player.
    Like so: robloxapp-20220725-1235348
    I also looked around the devfourm but couldn’t find something that worked for me.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the code to stop the player. It does succeed in not flinging but still passes the player through the walls

for i, v in pairs(game.Workspace.PlaceHolder:GetChildren()) do
	if not v:IsA("BasePart") or v.Name == "region" then return end
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if (character.HumanoidRootPart.Velocity * Vector3.new(1, 0, 1)).Magnitude > 18 then
				print("ran")
				humrp.Anchored = true
				game:GetService"RunService".Heartbeat:Wait()
				humrp.Velocity = Vector3.new()
				wait(0.2)
				humrp.Anchored = false
				local e = Instance.new("BodyVelocity", humrp)
				e.P = 1250
				e.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				e.Velocity = humrp.CFrame.lookVector*(-80)
				game.Debris:AddItem(e, 0.1)
			end
		end
	end)
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

for _, Descendant in ipairs(Character:GetDescendants()) do
	if not (Descendant:IsA("BasePart")) then continue end
	Descendant.AssemblyLinearVelocity = 0
	Descendant.AssemblyAngularVelocity = 0
end

https://developer.roblox.com/en-us/api-reference/property/BasePart/AssemblyLinearVelocity
https://developer.roblox.com/en-us/api-reference/property/BasePart/AssemblyAngularVelocity

1 Like