I just tried to make something simple where if the player is occupying a seat and holds W it moves forward. I don’t want it to move based on the the direction the players camera is facing or humanoid movement, just holding W means that the seat moves forward. It doesn’t work and I cant for the life of me figure out why. And ideas? Thanks.
local seat = script.Parent
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local speed = 16
local moving = false
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
if seat.Occupant then
moving = true
end
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
moving = false
end
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
if seat.Occupant and moving then
local currentCFrame = seat.CFrame
local forwardVector = currentCFrame.LookVector
local movementDelta = forwardVector * speed * deltaTime
seat.CFrame = currentCFrame + movementDelta
end
end)
Please help, thanks again!