Any way to disable movement with a script?

I want to make a script that moves you to a part when you press F

i am using humanoid:MoveTo() property on the player
but whenever i use it and the player moves it cancels it
i tried using

player.DevComputerMovementMode = Enum.DevComputerMovementMode.Scriptable

but it says i need permission 5 which is only for plugins
is there another way to disable the movement input without anchoring the player or setting the walkspeed to 0?

ContextActionService is used for disabling player input based on this post, works both on keyboard and controllers too.

2 Likes

Here’s a similar topic I had. This may help

1 Like

Simple way on a client script:
game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = true

this should work ofc there are other solutions for this that are better but this is how i rush those little things.

You can use UserInputService to detect when the “F” key is pressed and then disable the default keyboard input for movement while your script is executing. Here’s an example code, that should do what you want:

local UserInputService = game:GetService(“UserInputService”)
local humanoid = game.Players.LocalPlayer.Character.Humanoid

local function moveToPart(part)
local success, message = pcall(function()
humanoid:MoveTo(part.Position)
end)

if not success then
    warn("Failed to move to part:", message)
end

end

local function onKeyPressed(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F and not gameProcessedEvent then
UserInputService.OverrideMouseIconBehavior = Enum.OverrideMouseIconBehavior.ForceHide
UserInputService.OverrideMouseIconEnabled = true
UserInputService.ModalEnabled = true
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false
UserInputService.KeyboardEnabled = false
moveToPart(workspace.PartToMoveTo)
UserInputService.OverrideMouseIconEnabled = false
UserInputService.ModalEnabled = false
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserInputService.KeyboardEnabled = true
end
end

UserInputService.InputBegan:Connect(onKeyPressed)

1 Like

i specifically wrote not to anchor the player

Where do I put this script? I need it because I also need a way to prevent player from moving.

By the look of the reply the person sent, you should put it in a local script under starterplayerscripts

than this should be your solution i think it disables the player module so you should keep the humroot aunanchored and u can still have the humwalkspeed on whatever Roblox - How to Stop/Disable Player Movement - YouTube

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.