How can i make an script so my snowmobile can jump with the player if they are on the car

Im making an obby where you are on snow and gotta use an snowmobile to go through obstacles, i got the snowmobile done and the map done but i cant figure out how to make so the player can jump inside the snowmobile and the snowmobile goes up with the player as there is obstacles that you need to jump i dont know if i explained good.

1 Like

Hello, I have made a script for your request. Try it out and if something is not working then inform me

Code:

-- Edit the names to whatever it is
local vehicleSeat = script.Parent:FindFirstChild("VehicleSeat")
local snowmobile = script.Parent

-- Constants
local jumpForce = 1000 -- Adjust the force here

local function applyJump()
    local humanoid = vehicleSeat.Occupant
    if humanoid then
        -- Apply force
        humanoid:Move(Vector3.new(0, jumpForce, 0), true)
       
        local bodyVelocity = Instance.new("BodyVelocity")
        bodyVelocity.Velocity = Vector3.new(0, jumpForce / humanoid.Mass, 0)
        bodyVelocity.P = 1250 -- Adjust as needed
        bodyVelocity.Parent = snowmobile.PrimaryPart
        game.Debris:AddItem(bodyVelocity, 0.2)
    end
end

-- Detect the player's jump
vehicleSeat.ChildAdded:Connect(function(child)
    if child:IsA("Humanoid") then
        local humanoid = child
        humanoid.Jumping:Connect(function(isJumping)
            if isJumping then
                applyJump()
            end
        end)
    end
end)

It does not work even modifying it and does not give any error.

You can use ContextActionService and bind your jump keys to your snowmobile jump function and sink the inputs.

1 Like

Alright, then try this script

local vehicleSeat = script.Parent:FindFirstChild("VehicleSeat")
local snowmobile = script.Parent

-- Constants
local jumpForce = 1000 -- Adjust the force here

local function applyJump()
    local humanoid = vehicleSeat.Occupant
    if humanoid then
        print("Applying jump")
        -- Apply force
        humanoid:Move(Vector3.new(0, jumpForce, 0), true)

        -- Apply force to the snowmobile
        if snowmobile.PrimaryPart then
            local bodyVelocity = Instance.new("BodyVelocity")
            bodyVelocity.Velocity = Vector3.new(0, jumpForce / humanoid.Mass, 0)
            bodyVelocity.P = 1250 -- Adjust as needed
            bodyVelocity.Parent = snowmobile.PrimaryPart
            game.Debris:AddItem(bodyVelocity, 0.2)
        else
            warn("PrimaryPart is not set for the snowmobile")
        end
    else
        warn("Humanoid is not found in the vehicle seat")
    end
end

-- Detect the player's jump
vehicleSeat.ChildAdded:Connect(function(child)
    if child:IsA("Humanoid") then
        local humanoid = child
        print("Humanoid added to vehicle seat")
        humanoid.Jumping:Connect(function(isJumping)
            if isJumping then
                applyJump()
            end
        end)
    else
        warn("Child added to vehicle seat is not a humanoid")
    end
end)

Could you give an example of it please?

Refer to the documentation on how to use ContextActionService: ContextActionService | Documentation - Roblox Creator Hub

They provide very clear details along with examples to help you get started.

This script its made by an AI LOL

No it isn’t, tell me what made you think that.