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.
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.
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.
the prints and warns, aint no dev writing out that much for a debug line
If the player is always on the snowmobile consider making it a part of the player. Otherwise I believe you could set the players jump power to 0 and they will be unable to get out of the seat. Then you can make a button that restores their jump power and sets humanoid.Jump to true