-- Get the character and humanoid
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
-- Set the movement speed
local movementSpeed = 16
-- Function to handle character movement
local function moveCharacter()
local moveDirection = Vector3.new(0, 0, 0)
local userInput = game:GetService("UserInputService")
-- Keybindings for movement
local keybindings = {
[Enum.KeyCode.W] = Vector3.new(0, 0, -1),
[Enum.KeyCode.A] = Vector3.new(-1, 0, 0),
[Enum.KeyCode.S] = Vector3.new(0, 0, 1),
[Enum.KeyCode.D] = Vector3.new(1, 0, 0)
}
-- Calculate move direction based on keybindings
for keycode, direction in pairs(keybindings) do
if userInput:IsKeyDown(keycode) then
moveDirection = moveDirection + direction
end
end
-- Normalize and scale move direction
moveDirection = moveDirection.Unit * movementSpeed
-- Move the character
humanoid:Move(moveDirection)
end
-- Bind the moveCharacter function to the character's Move event
humanoid.Move:Connect(moveCharacter)
To use this script, you can create a LocalScript in Roblox Studio and place it inside the character or a descendant of the character. When you play the game, the character will move based on the W, A, S, D keys. You can adjust the movementSpeed variable to change the character's movement speed according to your preference.