local Climb = {
InputBegan = function()
if Humanoid.FloorMaterial ~= Enum.Material.Air then return end
local LookVector = HumanoidRootPart.CFrame.LookVector
local RayOrigin = HumanoidRootPart.Position + V3new(0, -0.5, 0)
local RayDestination = RayOrigin + V3new(2,0,2) * LookVector
local RayCheck = Rnew(RayOrigin, RayDestination - RayOrigin)
local part, position, normal = workspace:FindPartOnRay(RayCheck, Character)
if part then
if Head.Position.Y + 2 < part.Position.Y + part.Size.Y / 2 then return end
local GripPosition = V3new(
position.X,
part.Position.Y + part.Size.Y / 2,
position.Z
)
local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = V3new(huge,huge,huge)
BodyPosition.P = 50000
BodyPosition.D = 1500
BodyPosition.Position = GripPosition - normal + V3new(0,1.5,0)
local BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = V3new(huge,huge,huge)
BodyGyro.P = 500000
BodyGyro.D = 1500
BodyGyro.CFrame = CFnew(position, position - normal)
BodyGyro.Parent = HumanoidRootPart
BodyPosition.Parent = HumanoidRootPart
Humanoid.HipHeight = -1
wait(0.4)
Humanoid.HipHeight = 0
BodyGyro:Destroy()
BodyPosition:Destroy()
end
end,
InputEnded = function()
end
}
Performance looks fine, if there are any issues they’ll be with how the function is used (e.g. being called a lot of times). If the function is being run every time UserInputService.InputBegan fires that will not be very good as inputs happen a lot, but I assume you are not doing that.
You can make it look organised by adding an empty line between different components, as well as using a consistent naming convention:
if Humanoid.FloorMaterial ~= Enum.Material.Air then return end
local LookVector = HumanoidRootPart.CFrame.LookVector
local RayOrigin = HumanoidRootPart.Position + V3new(0, -0.5, 0)
local RayDestination = RayOrigin + V3new(2,0,2) * LookVector
local RayCheck = Rnew(RayOrigin, RayDestination - RayOrigin)
local Part, Position, Normal = workspace:FindPartOnRay(RayCheck, Character)
if Part then
if Head.Position.Y + 2 < Part.Position.Y + Part.Size.Y / 2 then return end
local GripPosition = V3new(
position.X,
part.Position.Y + part.Size.Y / 2,
position.Z
)
local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = V3new(Huge,Huge,Huge)
BodyPosition.P = 50000
BodyPosition.D = 1500
BodyPosition.Position = GripPosition - Normal + V3new(0,1.5,0)
BodyPosition.Parent = HumanoidRootPart
local BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = V3new(Huge,Huge,Huge)
BodyGyro.P = 500000
BodyGyro.D = 1500
BodyGyro.CFrame = CFnew(Position, Position - Normal)
BodyGyro.Parent = HumanoidRootPart
Humanoid.HipHeight = -1
wait(0.4)
Humanoid.HipHeight = 0
BodyGyro:Destroy()
BodyPosition:Destroy()
end
2 Likes