Cancel movement not working

So my game has a feature in which you can only move your character by performing a certain action in-game, you are unable to move your character normally by pressing WASD keys.
This works flawlessly in Roblox Studio, but it sometimes doesn’t work and lets me move my character with WASD when I visit the game normally. This problem might be triggered if I tab out while joining the game and tab back in btw.

LocalScript in StarterPlayerScripts:

local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()

repeat wait() until game.Players.LocalPlayer.Character
Controls:Disable()

Have you tried just disabling the humanoid’s walkspeed? (Setting it to 0)

1 Like

Not viable since exploiters can just set it in a while true loop or some sort of loop in the client. Also, it could conflict with a lot of scripts.

I think you could fix this issue by removing the line containing “repeat wait() until game.Players.LocalPlayer.Character.” The script would look like this:

local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()

Controls:Disable()

I did that because I had the same problem and I tried to fix it.

I’m using :Move() so if the walkspeed will be 0 you wont move.

Maybe try literally disabling the script that manages controls.
And if you’re worried about exploiters enabling it again, just kick them if it re-enabled in a certain amount of time.

I think :Move() is used to indicate the direction in which the player should move. By going to the Explorer → StartPlayer → Properties → Character → CharacterWalkSpeed and changing the value to 0, you should be able to accomplish your goal

I did exactly that but now my character can’t move at all.

Is there possibly a way to disable player movement but to allow :Move()?

Okay, I managed to fix it. I put a server script inside ServerScriptService and inside of it I put:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
    	player.DevComputerMovementMode = 'Scriptable'
    	player.DevTouchMovementMode = 'Scriptable'
    end)
end)