How can I fix these mobile controls for a custom character?

I’m basically trying to make a custom character, and I’m trying to expand to mobile users as well.
However, the script I currently have just doesn’t seem to work at all. It feels very unresponsive and buggy. I simply want the custom character to go in the direction the thumbstick is.

Example Video:

You can try it here on a mobile device.
https://www.roblox.com/games/5296406858/Playable-Rock

Script:

function checknan(xnum)
	local val = 0/0
	if xnum ~= val then
		return true
	else
		return false
	end
end

function GetInputDirection()
	local Controller = require(player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
	local MovementVector = Controller:GetMoveVector()
	local CameraLook = workspace.CurrentCamera.CFrame.LookVector
	local Offset = CFrame.new(Vector3.new(),Vector3.new(CameraLook.x,0,CameraLook.z))*MovementVector
	local InputDirection = Offset.unit
	return InputDirection
end

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled
   and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface() then
	--mobile player
	
	while true do
			local acc = char.Force.Value --desired acceleration
			local hrp = char:WaitForChild("HumanoidRootPart")
		
			hrp.BodyForce.Force = (GetInputDirection() - hrp.Position).Unit * hrp:GetMass() * acc
			hrp.BodyForce.Force = Vector3.new(hrp.BodyForce.Force.X, 0, hrp.BodyForce.Force.Z)
		
			print(checknan(hrp.BodyForce.Force.X))		
		
			if checknan(hrp.BodyForce.Force.X) == true then
				hrp.BodyForce.Force = Vector3.new(0, 0, 0)
			end
		
			print(hrp.BodyForce.Force)
			RunService.Stepped:Wait()
		end

How can I fix this?
No errors, local script in StarterCharacterScripts

Here is the composition of the custom character if needed
image
I would really appreciate a fix asap because I am hoping to allow my friends to come to join my game (Who don’t have access to a PC).

1 Like

If any clarification is needed I’ll be here

Solution found, while it isnt what i exactly wanted, I just used the player’s “mouse” through GetMouse()and made the rock roll towards it using

(mouse.Hit.p - hrp.Position).Unit * hrp:GetMass() * acc

HOWEVER, this setup is horrible for mobile users (to go forward) since their finger will be in the way of the game play. i have just found that out while testing

does anyone have an idea of what’s wrong?

1 Like

I have fixed an issue!
I fixed the NAN errors causing the character to disappear, however, the new script does not receive any force from the touchpad at all.
new script will be edited in