i don’t think the current core scripts use those names anymore in the first place but even if it did… The reason putting your local script in the Replicated First doesn’t work is because, well, anything in the replicated storage replicates first before the character scripts are loaded, and before any movement keys are binded, meaning that unbinding before a bind actually exists won’t do anything. You could yield and wait for everything to load and what not, but i’d argue the replicated first storage isn’t ideal for that. Placing your local script in the ServerScriptService doesn’t work because as the name implies it’s for server scripts, not local scripts. You should be placing your local script somewhere like the starter character/player scripts or the StarterGui.
However, whether or not the snippet you provided actually works or not i think a much more elegant solution to your problem would to sink the enums associated with forward and backward character movement instead, which yields the ability to enable and disable player movement more dynamically and i would say reduce the risk that a core script update could break your script.
You can sink the foward and backward keys by doing:
local ContextActionService =game:GetService("ContextActionService")
local FowardMovement = Enum.PlayerActions.CharacterForward
local BackwardMovement = Enum.PlayerActions.CharacterBackward
local function Sink()
return Enum.ContextActionResult.Sink
end
----Sink forward movement
ContextActionService:BindAction("SinkFowardMovement", Sink,false,FowardMovement)
----Sink backward movement
ContextActionService:BindAction("SinkBackwardMovement",Sink,false,BackwardMovement)
And to unsink (allow the player to move again you can unbind the action using the name you gave it ("SinkBackwardMovement"
or "SinkFowardMovement"
in this case)
---Alow the player to move freely again
ContextActionService:UnbindAction("SinkFowardMovement")
ContextActionService:UnbindAction("SinkBackwardMovement")
Edit:
Just some extra information and thoughts, unbinding or sinking any of the Playeractions
(including using the name associated with the bindings) actually don’t affect mobile or console player movement, because they don’t use any of those enums, but most importantly they don’t use separate enumerations for movement direction (unlike keyboard movement), console thumbstick movement only uses one enum to bind to Enum.KeyCode.Thumbstick1
and infact i don’t think the mobile thumbstick uses action binding at all!
Also if you were wondering the new names for keyboard player movement is:
"moveForwardAction"
"moveBackwardAction"
"moveLeftAction"
"moveRightAction"
"jumpAction"
But like i said, sinking is Likely better in the case that these names are changed and because of the other reasons i mentioned above.