I want to make a game where you move only using buttons on screen, so I need to unbind the movement buttons, but I have no idea how. I don’t even know what kind of script do I need to use, I barely know something about scripting.
You can achieve this by going into the Roblox’s movement script and changing a bit, then just copy the script and paste it into StarterPlayerScripts like this:
https://streamable.com/s71aac
The video might have not yet processed btw.
This will freeze all input action including camera rotation and player movement. It also disables the onscreen joystick on mobile/iPad/tablets etc. Place this code in a LocalScript in StarterPlayerScripts.
--=================================================================================
-- Services
--=================================================================================
local UserInputService = game:GetService("UserInputService");
local ContextActionService = game:GetService("ContextActionService");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local ServerStorage = game:GetService("ServerStorage");
--=================================================================================
-- Make the Bindable event in ReplicatedStorage, uncomment the next line and the
-- corresponding hook at the end of the script to create a local Bindable event
-- so you can call this from elsewhere on the client
--local freezePlayerBind = ReplicatedStorage:WaitForChild("FreezePlayer",3); -- bindable event (client->client)
--=================================================================================
-- Make the Remote event in ServerStorage and uncomment the next line, and the
-- corresponding hook at the end of the script to create a Remote event
-- so you can call this from the server
--local freezePlayerRemote = ServerStorage:WaitForChild("FreezePlayer",3); -- remote event (server->client)
--=================================================================================
-- local variables
--=================================================================================
local FreezeCount = 0; -- counter to keep track of Freeze/Unfreeze mismatches
local FREEZE_PLAYER = "FreezePlayer"; -- constant string to bind this action to
--=================================================================================
-- this returns all ContextActions as Sink, so overrides them all until it's unbound
--=================================================================================
function actionSink()
return Enum.ContextActionResult.Sink;
end
--=================================================================================
local function doFreeze()
-- freeze user input, and hide onscreen joystick...
UserInputService.ModalEnabled = not UserInputService.ModalEnabled;
ContextActionService:BindAction(FREEZE_PLAYER,
actionSink,false,unpack(Enum.PlayerActions:GetEnumItems()));
end
--=================================================================================
local function undoFreeze()
-- unfreeze user input, and show onscreen joystick...
UserInputService.ModalEnabled = not UserInputService.ModalEnabled;
ContextActionService:UnbindAction(FREEZE_PLAYER);
end
--=================================================================================
-- You should only ever call this function and nothing else in this script.
-- Do it with Bindable events or Remote events
--=================================================================================
function doFreezeAction(freeze : boolean)
-- request to freeze player
if freeze == true then
if FreezeCount == 0 then -- if this is not zero then we have an unpaired freeze/unfreeze
doFreeze();
FreezeCount += 1;
print("Freezing Action");
else
warn("Un-paired Freeze detected");
end
-- request to unfreeze player
elseif freeze == false then
if FreezeCount == 1 then -- if this is not one then we have an unpaired freeze/unfreeze
undoFreeze();
FreezeCount -= 1;
print("Un-Freezing Action");
else
warn("Un-paired Un-freeze detected");
end
end
end
--=================================================================================
-- Bindable event if you want to fire from client->client
--freezePlayerBind.Event:Connect(doFreezeAction);
--=================================================================================
-- Remote event if you want to fire from server->client
--freezePlayerRemote.OnClientEvent:Connect(doFreezeAction);
--
--=================================================================================
-- EOF..
--=================================================================================
You could use what @dduck5tar said, or use this simpler version:
-- local script in StarterGUI
local playerconfig = require(game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local ctrls = playerconfig:GetControls()
--to disable player controls
ctrls:Disable()
--to enable player controls
ctrls:Enable()
1 Like
Succinct example, I haven’t tried this method but will certainly give it a shot, Does it stand up on PC, iPhone, Tablet, and XBOX?
Not sure. I have only tested it on laptop.