Hello, I've been trying to script some custom movement.

local uis = game:GetService('UserInputService')
local players = game:GetService('Players')
local run = game:GetService('RunService')

local player = players.LocalPlayer
local camera = workspace.CurrentCamera

local function GetMass(bin)
	local mass = 0
	
	for _, v in pairs (bin:GetDescendants()) do
		if (v:IsA('BasePart')) then
			mass = (mass + v:GetMass())
		end
	end
	
	return mass
end

run.RenderStepped:Connect(function()
	local character = player.Character
	local rootpart = (character) and character:FindFirstChild('HumanoidRootPart')
	
	if (rootpart) then
		local BodyForce = rootpart:FindFirstChild('BodyForce') or Instance.new('BodyForce')
		
		local WalkSpeed = 24
		local MoveDirection = Vector3.new(0, 0, 0)
		
		if (uis:IsKeyDown(Enum.KeyCode.W)) then
			MoveDirection = (MoveDirection + Vector3.new(0, 0, 1))
		end
		
		if (uis:IsKeyDown(Enum.KeyCode.S)) then
			MoveDirection = (MoveDirection - Vector3.new(0, 0, 1))
		end
		
		if (uis:IsKeyDown(Enum.KeyCode.A)) then
			MoveDirection = (MoveDirection - Vector3.new(1, 0, 0))
		end

		if (uis:IsKeyDown(Enum.KeyCode.D)) then
			MoveDirection = (MoveDirection + Vector3.new(1, 0, 0))
		end
		
		local CameraCF		= camera.CFrame
		
		local RightVector 	= CameraCF.RightVector
		local UpVector 		= Vector3.new(0, 1, 0) 
		local FrontVector 	= -(RightVector:Cross(UpVector))
		local MoveVector 	= (FrontVector * MoveDirection.Z) + (RightVector * MoveDirection.X)
		
		local Mass = GetMass(character)
		
		BodyForce.Force = MoveVector * Mass * WalkSpeed
		BodyForce.Parent = rootpart
	end
end)

I have no clue why the BodyForce won't move the character.

2 comments

0

try using bodyvelocity instead and then doing [what ever you named it].MaxForce = Vector3.new("inf","inf","inf") so it will move the player under any circumstance.

0

I don't see your reasoning behind that. BodyForce Values are obviously changing when looking into the Explorer just not moving the Character.