im making a script where the player flies and he goes to where he looks at, but it doesn’t work no errors, it is a client script located in starterplayerscripts
script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local PLAYER_SPEED = 16 -- Speed of the player
local SMOOTHNESS = 0.2 -- Smoothness factor for movement
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("Torso")
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local moveDirection = Vector3.new(0, 0, 0)
local function updateMoveDirection()
local lookVector = camera.CFrame.LookVector
moveDirection = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
end
local function movePlayer(deltaTime)
if moveDirection.Magnitude > 0 then
local targetPosition = torso.Position + (moveDirection * PLAYER_SPEED * deltaTime)
torso.CFrame = torso.CFrame:Lerp(CFrame.new(targetPosition, torso.Position + moveDirection), SMOOTHNESS)
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.W then
updateMoveDirection()
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.W then
moveDirection = Vector3.new(0, 0, 0)
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
movePlayer(deltaTime)
end)