local Player = game.Players.LocalPlayer
local char = Player.Character
local mouse = game.Players.LocalPlayer:GetMouse()
local uis = game:GetService("UserInputService")
local position = mouse.Hit.p
local function grapple()
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- grab local player
local localPlayer = Players.LocalPlayer
-- create beam
local beam = Instance.new("Beam")
beam.Segments = 1
beam.Width0 = 0.2
beam.Width1 = 0.2
beam.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam.FaceCamera = true
-- create attachments
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1
-- parent attachments to Terrain
beam.Parent = workspace.Terrain
attachment0.Parent = workspace.Terrain
attachment1.Parent = workspace.Terrain
-- grab the mouse
local mouse = localPlayer:GetMouse()
-- connect to RenderStepped (update every frame)
-- make sure the character exists
local character = localPlayer.Character
if not character then
-- disable the beam
beam.Enabled = false
return
end
-- make sure the head exists
local head = character:FindFirstChild("Head")
if not head then
-- disable the beam
beam.Enabled = false
return
end
-- enable the beam
beam.Enabled = true
-- define origin and finish
local origin = head.Position
local finish = mouse.Hit.p
-- move the attachments
attachment0.Position = origin
attachment1.Position = finish
wait(1)
local bv = Instance.new("BodyVelocity")
bv.Parent = char.HumanoidRootPart
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = char.HumanoidRootPart.Velocity * finish.Magnitude
wait(.1)
bv:Destroy()
attachment0:Destroy()
beam:Destroy()
attachment1:Destroy()
end
uis.InputBegan:Connect(function(i)
if i.KeyCode == Enum.KeyCode.LeftShift then
grapple()
end
end)
I don’t really even know where to start here
uhh over where theres all the bodyvelocity stuff. how do i even get my rootpart to fly towards the part where the ray hit?