To create a Roblox Lua script for an ODM gear with linear velocity and mouse position, you can follow the logic you provided. Here's a script that implements this behavior:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local userInputService = game:GetService("UserInputService")
local odmGear = script.Parent -- Assuming the script is placed inside the ODM gear part
local hookPart = odmGear.HookPart -- Assuming the "hook" part is a child of the ODM gear part
local hookLaunched = false
local hookAnchored = false
local function onUserInput(input)
if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q then
if not hookLaunched then
local raycastParams = {
Filter = function(hit)
return hit.Part ~= hookPart and hit.Part ~= odmGear
end,
Inclusive = true
}
local hit = userInputService:Raycast(raycastParams)
if hit then
local character = hit.Character or hit.Hit
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local organizations = game:GetService("StarterGui"):GetEnabled()["CustomTeleportOrganizations"]
local tween = organizations:CreateTween(player, "LinearVelocity", Vector3.new(0, 20, 0), 0)
tween.Completed:Connect(function()
tween:Destroy()
hookLaunched = true
hookPart.Anchored = true
hookPart.Position = hit.Position
player.Character = nil
player.HumanoidRootPart.CanEnterVehicle = true
end)
end
end
end
elseif input.KeyCode == Enum.KeyCode.Escape then
hookLaunched = false
hookPart.Anchored = false
player.Character = odmGear
player.HumanoidRootPart.CanEnterVehicle = false
game:GetService("TeleportService"):Quit()
end
end
userInputService:RegisterWebLabelInput(onUserInput)
This script follows the logic you described:
- Player holds
E or Q and looks at an object.
- A raycast is performed to find the target object.
- If the target object is a character with a humanoid, the player's linear velocity is set to 0 and the character is anchored to the ODM gear.
- The player's character is set to nil, and the ODM gear is set as the player's character.
- If
E is released, the ODM gear is unanchored, and the player's character is set back to the original character.
Place this script inside the ODM gear part, and it should work as expected.