Skip to content

how to make a movement script for a fps in roblox studio

Updated: at 10:21 am

Table of contents

Open Table of contents

how to make a movement script for a fps in roblox studio

. Script Setup:

Open Roblox Studio and navigate to your FPS project.
In the Explorer window, find your character model.
Click the + icon next to the character's name and choose Script.

2. LocalScript for Movement:

This script will be placed inside the character and control movement with the WASD keys. Here’s the code with explanations for your game:

-- This script uses local input (WASD keys) to move the character

local character = script.Parent -- Get the character model

local speed = 16 -- Movement speed

local function updateMovement(dt) -- Function to update movement based on delta time
  local moveDir = Vector3.ZERO -- Initialize movement direction

  -- Check for key presses and update movement direction accordingly
  if character:FindFirstChild("Head").IsKeyDown("W") then
    moveDir.Z = moveDir.Z + 1
  elseif character:FindFirstChild("Head").IsKeyDown("S") then
    moveDir.Z = moveDir.Z - 1
  end

  if character:FindFirstChild("Head").IsKeyDown("A") then
    moveDir.X = moveDir.X - 1
  elseif character:FindFirstChild("Head").IsKeyDown("D") then
    moveDir.X = moveDir.X + 1
  end

  -- Normalize the movement direction to avoid diagonal speedup
  moveDir = moveDir.Unit

  -- Apply movement using Humanoid:Move with speed and dt for smooth motion
  character.Humanoid:Move(moveDir * speed * dt)
end

-- Use a loop to continuously update movement
game:GetService("RunService").Heartbeat:Connect(updateMovement)

That is it! Hang around for part TWO!!!