Sure, here's a possible implementation of the script you described:
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
-- Function to launch the hook
local function launchHook()
if not hookLaunched then
-- Play animation and sound
odmGear:PlayAnimation("Hook_Launch")
odmGear:PlaySound("Hook_Launch_Sound")
-- Set the hook's anchor point to the mouse position
hookPart.Anchored = true
hookPart.AnchorPoint = mouse.Hit.p
-- Set the hook's velocity to the mouse's velocity
hookPart.LinearVelocity = mouse.Hit.velocity
-- Set the hook launched flag to true
hookLaunched = true
end
end
-- Function to anchor the hook
local function anchorHook()
if hookLaunched and not hookAnchored then
-- Play animation and sound
odmGear:PlayAnimation("Hook_Anchor")
odmGear:PlaySound("Hook_Anchor_Sound")
-- Set the hook's anchor point to the part's origin
hookPart.Anchored = true
hookPart.AnchorPoint = odmGear.Part.Origin
-- Set the hook's velocity to zero
hookPart.LinearVelocity = Vector3.zero
-- Set the hook anchored flag to true
hookAnchored = true
end
end
-- Function to update the hook's position and animation
local function updateHook()
if hookLaunched and not hookAnchored then
-- Update the hook's position based on its velocity
hookPart.Position = hookPart.Position + hookPart.LinearVelocity * deltaTime
-- Check if the hook has reached the ground
local groundCheck = hookPart:Raycast(Vector3.down * 10, 10)
if groundCheck then
-- Anchor the hook and play the anchoring animation
anchorHook()
end
end
end
-- User input callback function
local function onUserInput(input, keyCode)
if input == "E" or input == "Q" then
if keyCode == Enum.KeyCode.LeftMouseButton then
-- Launch the hook
launchHook()
end
end
end
-- Initialize the script
hookPart.Anchored = false
hookPart.LinearVelocity = Vector3.zero
hookLaunched = false
hookAnchored = false
-- Set up the user input callback
userInputService:RegisterInputFunction(onUserInput)
-- Update the hook's position and animation
script.Parent.oupe dates:Connect(updateHook)
This script will launch the hook when the user clicks the left mouse button while holding either the "E" or "Q" key. It will then anchor the hook to the part's origin and play the anchoring animation. The hook's position will be updated based on its velocity until it reaches the ground, at which point it will be anchored.
Note that this script assumes that the "hook" part is a child of the ODM gear part, and that it has an animation named "Hook_Launch" and "Hook_Anchor". It also assumes that the ODM gear part has a sound named "Hook_Launch_Sound" and "Hook_Anchor_Sound". You may need to adjust the script to match the names of your parts and animations.