Skip to content
The Chat Archive
gpt-4.1-2025-04-14· OpenAI LMArena Human Preference 140K

Make a roblox script that makes you unable to move forward or backwords.

  1. User

    Make a roblox script that makes you unable to move forward or backwords.

  2. Assistant

    Certainly! If you want to prevent a player from moving forward or backward in Roblox (i.e., block the W and S keys, or up/down movement), you can do this by manipulating the player's controls using a LocalScript.

    Here’s a simple script you can place in StarterPlayerScripts (so it runs for each player):

    -- Place this LocalScript in StarterPlayerScripts
    
    local UserInputService = game:GetService("UserInputService")
    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")
    
    -- Table of keys to block (W, S, UpArrow, DownArrow)
    local blockedKeys = {
        [Enum.KeyCode.W] = true,
        [Enum.KeyCode.S] = true,
        [Enum.KeyCode.Up] = true,
        [Enum.KeyCode.Down] = true,
    }
    
    -- Prevent forward/backward movement
    UserInputService.InputBegan:Connect(function(input, gameProcessed)
        if blockedKeys[input.KeyCode] then
            humanoid:Move(Vector3.new(0,0,0), false)
        end
    end)
    
    UserInputService.InputChanged:Connect(function(input, gameProcessed)
        if blockedKeys[input.KeyCode] then
            humanoid:Move(Vector3.new(0,0,0), false)
        end
    end)
    
    UserInputService.InputEnded:Connect(function(input, gameProcessed)
        if blockedKeys[input.KeyCode] then
            humanoid:Move(Vector3.new(0,0,0), false)
        end
    end)
    

    How it works:

    • This script listens for input events for the W, S, Up, and Down keys.
    • When any of these keys are pressed, changed, or released, it immediately sets the humanoid's movement vector to zero, effectively blocking forward and backward movement.
    • The player can still move left and right (A/D or Left/Right arrows).

    Note:
    This is a simple approach. For more robust control (especially with custom movement scripts or mobile controls), you may need to override the control module or use a custom movement system.

    Let me know if you need it to work with custom controls or for NPCs!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.