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

How to slow player fall from height?

Hi all!... Fairly new to Roblox Lua here (but not a stranger to coding in other languages)...

I'm simply trying to use BodyForce to slow the rate at which a player... not 100% certain I'm going about this correctly, but is what I've come up with thus far after some reading and messing around... everything executes, but the player still falls like a rock :)

Thanks y'all!!

local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local Character = ((LocalPlayer.Character and LocalPlayer.Character.Parent) and LocalPlayer.Character) or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local ToolEquipped = false
local TotalMass = 0

local Tool = LocalPlayer.Backpack:FindFirstChild("MyTool")

Tool.Equipped:Connect(function(mouse)
	print("Tool equipped")
	ToolEquipped = true
	for _, part in pairs(Character:GetChildren()) do
		if part:IsA("Part") then
			TotalMass += part:GetMass()
		end
	end
end)

Tool.Unequipped:Connect(function(mouse)
	print("Tool unequipped")
	ToolEquipped = false
	TotalMass = 0
end)

local function CreateBodyForce(Character)
	if ToolEquipped then
		local Hum = Tool.Parent:FindFirstChild("Humanoid")
		print("Cool, the Tool is equipped") 
		if Hum then
			local Force = -196.2 * TotalMass
			local BodyForce = Instance.new("BodyForce")
			BodyForce.Force = Vector3.new(0, Force, 0)
			BodyForce.Parent = Character.HumanoidRootPart
		end
	end
end

Humanoid.StateChanged:Connect(function(old,new)
	print("evaluating state change")
	if Humanoid.FloorMaterial == Enum.Material.Air then
		print("reached state change")
		local floor = Humanoid.FloorMaterial
		print("Floor is: ",floor)
		CreateBodyForce(Character)
	end
end)

3 comments

0

No offence, but this comment was not particularly helpful... if you have a look at the code, you'll see that I'm attempting to change the fall rate when a tool is equipped... not for the entire workspace :)

0

i think you made an error at local character as there is an extra (

0

If you look closely, that isn't actually an 'extra' brace... "((LocalPlayer.Character and LocalPlayer.Character.Parent) and LocalPlayer.Character)" OR "LocalPlayer.CharacterAdded:Wait()"

1 answer

Okay... resolved my issue.... in order to slow descent, multiplied the calculated force by 2

BodyForce.Force = Vector3.new(0, Force * 2, 0)

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