i can walk normally after the controls is enabled but when i die it auto disables.
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Disable()
wait()
controls:Enable()
i can walk normally after the controls is enabled but when i die it auto disables.
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Disable()
wait()
controls:Enable()
enable the controls again on spawn? meaning at the top of your localscript. aside from that why would you disable and enable the controls? if you want people being unable to move you should set the walkspeed to 0 or anchor their body
That’s not a good solution. There are cases in which player movement is necessary without allowing controls. Setting WalkSpeed to 0 does not disable controls and anchoring the body, unless you have a specific need to do so, is bad.
What you should be doing is passing a sink towards the ContextActionService that has a higher priority than the movement actions, which are set to default.
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindActionAtPriority("DisableMovement", function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.Default.Value + 25, Enum.PlayerActions:GetEnumItems())
This effectively disables controls, but requires any other input wanting WASD keys to be bound the same way at higher priorities.
I had the same problem after disableling the controls and the player died, the controls would stop working even if a used the Controls:Enable() after the player respawned, but this is how I fixed it.
Inside a local script inside StartedCharacterScripts folder I added this following code:
local LocalPlayer = game:GetService("Players").LocalPlayer
local playerModule = require(LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()
controls:Disable()
wait()
controls:Enable()
I put this before any of my functions(am guessing it could go anywhere as long as it gets excecuted at the beggening)
side note just know that any scripts inside StartedCharacterScripts will reset every time the player respawns