How would i make a custom vehicle seat?

All i need is how to get inputs from the player on the seat so the car doesn’t take off and make it server side

This belongs in #help-and-feedback:scripting-support

In order to make custom car seat you have to program drag, turning etc which will require a lot of physics.

And for inputs you can either use the InputBegan event or UserInputService:IsKeyDown().

Ok thanks! So yeah i will try and change this

EDIT: My VehicleSeat isnt running the repeat so im using while true do And it wont work
Well i have tried UserImputSystem:IsKeyDown() in a loop but it didnt change so i need to get the inputs from the seat

I believe a good option is to look at this module script for ideas on how to obtain input using event-based coding.

However, when I tried it out the issue was that the throttle only went from 0 to 1 and not -1 to 1 so it was hard to tell if the car is moving forwards or backward simply like the normal vehicle seat. So just keep this in mind and use a similar approach with user input services.

Also try not to use:

It gets really bad for certain scenarios like the free model jeep just look at that activity rate even when no one is sitting on the vehicle. This is because of the :GetDescendants() function which constant iterates through every part of the jeep in order to find the thrusters and change them.

However, even the free model jeep has some good ideas to take from such as the hierarchy based code and how it gives player the local script to detect input on seat which I modified below, and effectively make the script local side to ensure the fastest player input response.

Player local script giver code similar to free model jeep
--[[
    This is a server script which gives the player control on sit of the vehicle
    Places the script inside player gui to run like the jeep free model
]] -- Roblox Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Get this module script
local LocalMechScript = ReplicatedStorage.Source.ClientScripts:WaitForChild("MechHumanoidControl")

-- Get the local script stored in the module folder
-- Store it here as its constant
local playerLocalMechScript = LocalMechScript:Clone()

local function giveModelToPlayer(model, owner)
    local descendants = model:GetDescendants()

    for index, descendant in pairs(descendants) do
        if descendant:IsA("BasePart") then
            descendant:SetNetworkOwner(owner)
        end
    end
end
-- local humanoid root part

--[[
    Parameter mech pointer refers to the mech the script is in
    accessed from a server cript within the mech model
]]
local function MechController(mechPointer)

    -- Get the mech from the inputted path
    local mech = mechPointer

    local mechSeat = mech:WaitForChild("MechSeat")

    -- Basically give the player the local script on seat and remove
    mechSeat.Changed:Connect(function(property)

        -- If the change is within the occupant value
        if property == "Occupant" then
            --
            if mechSeat.Occupant then
                local player = game.Players:GetPlayerFromCharacter(
                                   mechSeat.Occupant.Parent)
                -- nill check for player for some reason
                if player then
                    print("player has entered the seat")
                    --mechSeat:SetNetworkOwner(player)
                    --mechRootPart:SetNetworkOwner(player)
                    giveModelToPlayer(mech,player)

                    -- Get the local script stored in the module folder
                    -- Gives the local script to the player
                    -- clone again cause it may be garbage collected
                    playerLocalMechScript = LocalMechScript:Clone()
                    playerLocalMechScript.Parent = player.PlayerGui
                    playerLocalMechScript.Disabled = false
                end
            else
                -- reset network ownership
                print("left seat")
                --mechSeat:SetNetworkOwner(nil)
                --mechRootPart:SetNetworkOwner(nil)
                giveModelToPlayer(mech,nil)

                -- If the script still exist then remove it server side
                if playerLocalMechScript then
                    print("Destroying the script on server")
                    playerLocalMechScript:Destroy()
                    playerLocalMechScript = nil
                else
                    print("script already destroyed locally ")
                end
            end
        end
    end)

end

return MechController

Then in a server script parented under the vehicle, I use this vehicle control giver module to connect the event to the seat part which gives executes the module script giving away the local script to the player and do some network property stuff.

--Require this script in replicated storage
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local mechControllerPointer = ReplicatedStorage.Source.ModuleFolder:WaitForChild("MechControlGiver")

local mechController = require(mechControllerPointer)

--set humanoid hip height
local humanoid = script.Parent:FindFirstChild("Humanoid")

--Give control of the model
mechController(script.Parent)
1 Like

Thanks! I will try and use this