Character not freezing?

So im trying to freeeze player controls as the game controls them for a bit… But the player can still move…

Code:

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

ContextActionService:BindActionAtPriority(
    FROZEN_ACTION_KEY,
    function() end,
    false,
    Enum. ContextActionPriority.High.Value,
    unpack(Enum.PlayerActions:GetEnumItems())
)

game.ReplicatedStorage.Pathfind2:InvokeServer()

ContextActionService:UnbindAction(FROZEN_ACTION_KEY)

Read bottom reply, for new code… Its still broken!

is there anything between

ContextActionService:BindActionAtPriority(
    FROZEN_ACTION_KEY,
    function() end,
    false,
    Enum. ContextActionPriority.High.Value,
    unpack(Enum.PlayerActions:GetEnumItems())
)

game.ReplicatedStorage.Pathfind2:InvokeServer()

and

ContextActionService:UnbindAction(FROZEN_ACTION_KEY)

cause if not then you are unbinding it just after binding it

the pathfind does not return until the player is at the destination so its yielding the script.

just to be 100% sure can you test by printing “this is a print” in between
game.ReplicatedStorage.Pathfind2:InvokeServer()
and
ContextActionService:UnbindAction(FROZEN_ACTION_KEY)

ok.

i shall print(“hi”)

no it does not print.

Okay,

local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("ControlScript"):WaitForChild("MasterControl"))

MasterControl:Disable() --disable movement
MasterControl:Enable() --disable movement

source: How to disable character movement while gamepad is navigating a GUI?

1 Like

so enable would make it so players can move again?

yes

I updated the code above to work in any localscript, I had it set up so it would only work if it was ran in a script in StarterPlayerScripts.

:Enabled() does not seem to be working… Sometimes it works… Sometimes it does not, I have been getting reports from players saying “I cant move.” and its all after their controls are disabled.

I am running the :Enabled() command.

Can you send a snippet of the code that runs the Enable part?

The problem with your original code is that you are using BindActionAtPriority, instead of just BindAction.

When using BindActionAtPriority, the function you provide should return a ContextActionResult that describes if you want to sink the inputs or pass the inputs to the next bound function.

1 Like

MasterControl:Enable()

What i meant was like the surrounding code that runs it, like is it inside a if or ?

inside nothing, the code after it runs fine but the code before it does not. Sometimes it works sometimes it does not.

Do you know whats wrong with it?

Hmm, I need a bit more information about how its being ran

fire away!

1 Like