Character not freezing?


#1

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!


#2

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


#3

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


#4

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)


#5

ok.


#6

i shall print(“hi”)


#7

no it does not print.


#8

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?


#9

so enable would make it so players can move again?


#10

yes


#11

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.


#12

: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.


#13

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


#14

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.


#15

MasterControl:Enable()


#16

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


#17

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


#18

Do you know whats wrong with it?


#19

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


#20

fire away!