Issues with the :MoveTo() and freezing Player Input

Hi there,

Right now, I’m using the @buildthomas method of freezing character input: How to temporarily disable all character input? - #6 by buildthomas

Which in the context of my code is:

local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"

Player.Character.Humanoid.WalkSpeed = 50 --So the player can more than match the speed of the person they are falling on
ContextActionService:BindAction( --Freezes player input but is incidentally freezing :MoveTo() as well
    FREEZE_ACTION,
    function()
 		return Enum.ContextActionResult.Sink -- need to explicitly return this
    end,
    false,
	unpack(Enum.PlayerActions:GetEnumItems())
)

Player.Character.Humanoid:MoveTo(Character.Torso.Position) --Is supposed to move the player to where the player is (gravity is letting them fall, but this mainly allows them to match X and Y position)
Animation1Track:Play() --Plays the jumping animation
wait(Animation1Track.Length)
Animation2Track:Play() --Plays the animation used for mid-fall
while (Character.Torso.Position.Y - TargetCharacter.Torso.Position.Y) > 5 do --Waits until the person is in the proper distance
	wait(.1)
end
Animation2Track:Stop() --Stops the falling animation
Animation3Track:Play() --Executes the landing/finishing animation
Player.Character.Humanoid.WalkSpeed = 16 --Resets walkspeed
ContextActionService:UnbindAction(FREEZE_ACTION) --Unfreezes player input

Because I am attempting to play an animation that occurs while the player is falling from a high point onto another player, it was necessary to freeze the input so that the animation didn’t get ruined, and I was using :MoveTo() so that the player would be able to follow the player they were landing on.

The problem is that when using this method, :MoveTo() ends up not working and the player does not move.

Are there any suggestions for how to circumvent the issue, utilizing a better way of locking out player input, etc.?

Hey there! I’ve had an issue with this in the past as well where I had to prevent users from inputting anything. I’ve solved it by disabling the character script! ROBLOX by default has a module called PlayerModule inside the player’s PlayerScript upon joining and you can disable the controls via the PlayerModule by doing so:

local playerModule = require(player.PlayerScripts:WaitForChild("PlayerModule"))
local control = playerModule:GetControls()
control:Disable() -- to disable player input
control:Enable() -- to enable player input

By disabling the player input, you do not have to change their walkspeed to 0 at all! It simply blocks their input; that’s literally it, you can have everything else the same (16 walkspeed) and it should work just fine!

Keep note that you can’t get the PlayerScripts via the server, so you’d have to use a localscript or use remotes to do so!

I’ve put together a simple :MoveTo() script using the GetControls() function.

local player = game.Players.LocalPlayer
local playerModule = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local control = playerModule:GetControls()

control:Disable()
player.Character:WaitForChild("Humanoid"):MoveTo(workspace.PointA.Position)

player.Character:WaitForChild("Humanoid").MoveToFinished:Connect(function(reached)
	control:Enable()
end)
6 Likes