can you swap left and right? "local UserInputService =…
- User
can you swap left and right? "local UserInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local player = Players.LocalPlayer
local BoatMovementEvent = ReplicatedStorage:WaitForChild("BoatMovementEvent")
local currentBoat = nil local isSeated = false
-- Detect when seated in a BoatSeat player.CharacterAdded:Connect(function(char) char:WaitForChild("Humanoid").Seated:Connect(function(seated, seat) if seated and seat and seat.Name == "BoatSeat" then currentBoat = seat:FindFirstAncestorOfClass("Model") isSeated = true else isSeated = false currentBoat = nil end end) end)
-- Handle key presses UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed or not isSeated or not currentBoat then return end
local key = input.KeyCode if key == Enum.KeyCode.W then BoatMovementEvent:FireServer(currentBoat, "Forward") elseif key == Enum.KeyCode.S then BoatMovementEvent:FireServer(currentBoat, "Backward") elseif key == Enum.KeyCode.A then BoatMovementEvent:FireServer(currentBoat, "Left") elseif key == Enum.KeyCode.D then BoatMovementEvent:FireServer(currentBoat, "Right") endend)
-- Optional: Stop movement when releasing keys UserInputService.InputEnded:Connect(function(input, gameProcessed) if gameProcessed or not isSeated or not currentBoat then return end
local key = input.KeyCode if key == Enum.KeyCode.W or key == Enum.KeyCode.S or key == Enum.KeyCode.A or key == Enum.KeyCode.D then BoatMovementEvent:FireServer(currentBoat, "Stop") endend)" bc it is mixed lol
- Assistant
Sure thing!
Below is the tiny tweak you need—just swap what gets sent for the A- and D-keys.
(The rest of your script can stay exactly the same.)-- Handle key presses UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed or not isSeated or not currentBoat then return end local key = input.KeyCode if key == Enum.KeyCode.W then BoatMovementEvent:FireServer(currentBoat, "Forward") elseif key == Enum.KeyCode.S then BoatMovementEvent:FireServer(currentBoat, "Backward") -- ▼ SWAPPED HERE ▼ elseif key == Enum.KeyCode.A then BoatMovementEvent:FireServer(currentBoat, "Right") -- A now turns RIGHT elseif key == Enum.KeyCode.D then BoatMovementEvent:FireServer(currentBoat, "Left") -- D now turns LEFT end end)InputEndeddoesn’t need to change because you’re still sending a generic"Stop"for any of the keys being released.That’s it—A will now rotate the boat to the right, and D will rotate it to the left. 🚤
- User
can you make it so you can move forward while turning bc it complete stops moving forward when turning :) :3
- Assistant
The issue
When any of the four keys is released your LocalScript fires
BoatMovementEvent:FireServer(...,"Stop").
On the server the"Stop"branch sets bothBoatStates[boat].move = "Stop" BoatStates[boat].turn = "Stop"so the second you lift either key the boat quits doing everything.
The fix
Send two independent stop-messages:
"StopMove"– only stops forward / backward."StopTurn"– only stops left / right.
That lets you keep holding W (move) while briefly tapping A or D (turn).
1️⃣ LocalScript (client)
local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local player = Players.LocalPlayer local evt = RS:WaitForChild("BoatMovementEvent") local currentBoat, isSeated = nil, false -- detect seat player.CharacterAdded:Connect(function(char) char:WaitForChild("Humanoid").Seated:Connect(function(seated, seat) if seated and seat and seat.Name == "BoatSeat" then currentBoat, isSeated = seat:FindFirstAncestorOfClass("Model"), true else currentBoat, isSeated = nil, false end end) end) -- key down ➜ start action UIS.InputBegan:Connect(function(input, processed) if processed or not isSeated or not currentBoat then return end local key = input.KeyCode if key == Enum.KeyCode.W then evt:FireServer(currentBoat, "Forward") elseif key == Enum.KeyCode.S then evt:FireServer(currentBoat, "Backward") elseif key == Enum.KeyCode.A then evt:FireServer(currentBoat, "Right") -- swapped elseif key == Enum.KeyCode.D then evt:FireServer(currentBoat, "Left") -- swapped end end) -- key up ➜ stop *specific* action UIS.InputEnded:Connect(function(input, processed) if processed or not isSeated or not currentBoat then return end local key = input.KeyCode if key == Enum.KeyCode.W or key == Enum.KeyCode.S then evt:FireServer(currentBoat, "StopMove") elseif key == Enum.KeyCode.A or key == Enum.KeyCode.D then evt:FireServer(currentBoat, "StopTurn") end end)
2️⃣ ServerScript (movement)
Only the
OnServerEventpart changes; the Heartbeat loop is still fine.local RS = game:GetService("ReplicatedStorage") local evt = RS:WaitForChild("BoatMovementEvent") local BoatStates = {} -- [boat] = { move = "Stop"/"Forward"/"Backward", -- turn = "Stop"/"Left"/"Right" } evt.OnServerEvent:Connect(function(player, boat, cmd) if not boat or not boat:IsA("Model") then return end local seat = boat:FindFirstChild("BoatSeat") if not seat or seat.Occupant ~= player.Character:FindFirstChildOfClass("Humanoid") then return end -- create record & define PrimaryPart if missing BoatStates[boat] = BoatStates[boat] or {move = "Stop", turn = "Stop"} boat.PrimaryPart = boat.PrimaryPart or seat local state = BoatStates[boat] -- movement if cmd == "Forward" or cmd == "Backward" then state.move = cmd elseif cmd == "StopMove" then state.move = "Stop" -- turning elseif cmd == "Left" or cmd == "Right" then state.turn = cmd elseif cmd == "StopTurn" then state.turn = "Stop" end end)(Leave the previously-supplied
Heartbeatloop as-is; it already uses
state.moveandstate.turnindependently.)
Result
- Hold W to go forward.
- While still holding W, tap A/D to steer—the boat keeps moving.
- Release A/D and it straightens out but continues forward until you finally release W (or press S).
Enjoy smooth sailing! 🚤
- User
it isnt stopping when i let go of the keys?
- Assistant
Ah, sorry about that — the “stop” packets probably never reach the server.
UserInputService.InputEndedcan fail to fire when several keys are pressed together or when Roblox has already processed the key.
We’ll switch to a state-polling approach that is rock-solid:- Keep booleans such as
isWDown,isADown, etc. - On every
RenderStepped(client-side frame) package the current state and send it to the server. - The server just stores the latest state and the Heartbeat loop uses
it.
(We’ll throttle the remote to 30 fps so we don’t spam the server.)
With this method the boat will instantly stop the moment all movement / turn keys are up.
1️⃣ RemoteEvent
ReplicatedStorage ⟶
BoatMovementEvent(already there)
2️⃣ LocalScript (StarterPlayerScripts)
--// Services local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local ReplicatedStorage = game:GetService("ReplicatedStorage") --// References local player = Players.LocalPlayer local remote = ReplicatedStorage:WaitForChild("BoatMovementEvent") --// Key-state table local keyDown = { W = false, S = false, A = false, D = false } local currentBoat = nil local isSeated = false --------------------------------------------------------------------- -- Seat detection --------------------------------------------------------------------- local function hookCharacter(char) local hum = char:WaitForChild("Humanoid") hum.Seated:Connect(function(seated, seat) if seated and seat and seat.Name == "BoatSeat" then currentBoat = seat:FindFirstAncestorOfClass("Model") isSeated = true else isSeated = false currentBoat = nil -- clear keys so we don't keep sending "true" for k in pairs(keyDown) do keyDown[k] = false end end end) end if player.Character then hookCharacter(player.Character) end player.CharacterAdded:Connect(hookCharacter) --------------------------------------------------------------------- -- Track InputBegan / InputEnded --------------------------------------------------------------------- local function setKey(keyCode, state) if keyCode == Enum.KeyCode.W then keyDown.W = state elseif keyCode == Enum.KeyCode.S then keyDown.S = state elseif keyCode == Enum.KeyCode.A then keyDown.A = state elseif keyCode == Enum.KeyCode.D then keyDown.D = state end end UserInputService.InputBegan:Connect(function(inp, processed) if processed then return end setKey(inp.KeyCode, true) end) UserInputService.InputEnded:Connect(function(inp, processed) if processed then return end setKey(inp.KeyCode, false) end) --------------------------------------------------------------------- -- Send state 30 fps while seated --------------------------------------------------------------------- local accum = 0 RunService.RenderStepped:Connect(function(dt) if not isSeated or not currentBoat then return end accum += dt if accum < 1/30 then return end -- throttle to ~30 fps accum = 0 -- compact state so we only send when something changed local state = { Fwd = keyDown.W, Back= keyDown.S, Left= keyDown.D, -- << swapped! (D = left, A = right) Right= keyDown.A } remote:FireServer(currentBoat, state) end)Notes
• The swap requested earlier is still here: D = Left and A = Right
• No more “StopMove / StopTurn” packets; we just send the four booleans every 1⁄30 s.
3️⃣ ServerScript (ServerScriptService or boat model)
--------------------------------------------------------------------- -- Settings --------------------------------------------------------------------- local MOVE_SPEED = 15 -- studs / second local TURN_SPEED = 1.5 -- radians / second --------------------------------------------------------------------- local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local remote = ReplicatedStorage:WaitForChild("BoatMovementEvent") -- [boat] = { Fwd = false, Back = false, Left = false, Right = false } local boatStates = {} --------------------------------------------------------------------- -- Heartbeat : move every frame --------------------------------------------------------------------- RunService.Heartbeat:Connect(function(dt) for boat, st in pairs(boatStates) do if not boat:IsDescendantOf(workspace) or not boat.PrimaryPart then boatStates[boat] = nil continue end local cf = boat:GetPrimaryPartCFrame() local newCF = cf -- forward / backward local dir = 0 if st.Fwd then dir = 1 elseif st.Back then dir = -1 end if dir ~= 0 then local move = cf.LookVector * dir * MOVE_SPEED * dt newCF = newCF + Vector3.new(move.X, 0, move.Z) end -- left / right local turn = 0 if st.Left then turn = -1 elseif st.Right then turn = 1 end if turn ~= 0 then newCF = newCF * CFrame.Angles(0, turn * TURN_SPEED * dt, 0) end if newCF ~= cf then boat:SetPrimaryPartCFrame(newCF) end end end) --------------------------------------------------------------------- -- Remote handler --------------------------------------------------------------------- remote.OnServerEvent:Connect(function(player, boat, state) -- security checks if not boat or not boat:IsA("Model") then return end local seat = boat:FindFirstChild("BoatSeat") if not seat or not seat.Occupant or seat.Occupant.Parent ~= player.Character then return end -- initialise if not boatStates[boat] then boat.PrimaryPart = boat.PrimaryPart or seat boatStates[boat] = {Fwd=false,Back=false,Left=false,Right=false} end -- copy booleans for k,v in pairs(state) do boatStates[boat][k] = v and true or false end end)Now:
• Hold W → moves forward
• While still holding W, press A (turn-right) or D (turn-left)
The boat keeps moving and turning.
• Release A / D → turning stops, forward continues.
• Release W → movement stops immediately.Because the client streams the key states every 1⁄30 s, letting go of a key reliably tells the server to stop that action. No more “it keeps going”! 🚤👍
- Keep booleans such as
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.