You can make use of ContextActionService for this. Originally posted by TheGamer101:
local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"
ContextActionService:BindAction(
FREEZE_ACTION,
function()
return Enum.ContextActionResult.Sink
end,
false,
unpack(Enum.PlayerActions:GetEnumItems())
)
-- To unfreeze movement:
ContextActionService:UnbindAction(FREEZE_ACTION)
On a side note, in the future please read the guidelines for this category before posting, and use the search feature to see if your question has already been answered.