Here is the entire script:
UIS.InputBegan:Connect(function(Key, Cant)
if Key.KeyCode == Enum.KeyCode.Space and Cant == false and ClimbCd == false and Stun.Value == 0 and Falling.Value == true then
spawn(function()
ClimbCd = true
wait(3)
ClimbCd = false
end)
local RegionSize = Vector3.new(3,3,3)
local RegionPos = RootPart.Position + (RootPart.CFrame.LookVector * 0.6) + Vector3.new(0,2,0)
local Region = Region3.new(RegionPos-(RegionSize/2),RegionPos+(RegionSize/2))
local Parts = workspace:FindPartsInRegion3(Region,Character,20)
local FinalPosition
local Table = {}
local HighestValue = 0
for _, v in ipairs(Parts) do
local Top = v.CFrame * CFrame.new(0,v.Size.Y/2,0)
local TopMin = v.CFrame * CFrame.new(-v.Size.X/2,v.Size.Y/2,-v.Size.Z/2)
local TopMax = v.CFrame * CFrame.new(v.Size.X/2,v.Size.Y/2,v.Size.Z/2)
local MinX = TopMin.X
local MaxX = TopMax.X
local MinZ = TopMin.Z
local MaxZ = TopMax.Z
local PosX = RegionPos.X
local PosZ = RegionPos.Z
local X = math.clamp(PosX, MinX, MaxX)
local Z = math.clamp(PosZ, MinZ, MaxZ)
local Y = Top.Y
local Position = Vector3.new(X,Y,Z)
local Raycast = Ray.new(Position, Position+Vector3.new(0,0.5,0))
local RayPart = workspace:FindPartOnRay(Raycast,Character)
if RayPart == nil then
table.insert(Table, Position)
end
end
for _, s in ipairs(Table) do
local Number = s.Y -- Number is a Vector3 value, s.Y is the Y coordinate
print("Number") -- this WORKS and returns 7.5 in my case
if (Number > HighestValue and s) then -- error, HighestValue equals to 0
HighestValue = Number
end
end
FinalPosition = Vector3.new(HighestValue)
if FinalPosition ~= nil then
local Distance = (RegionPos - FinalPosition).magnitude
if Distance <= 1.5 then
local BV = Instance.new("BodyPosition")
BV.Parent = RootPart
BV.MaxForce = Vector3.new(36000,36000,36000)
BV.Position = RootPart.Position+RootPart.CFrame.LookVector*2+Vector3.new(0,5,0)
BV.P = 32000
game.Debris:AddItem(BV, 1.1)
ClimbAnim:Play()
game.ReplicatedStorage.Events.ClimbSound:FireServer()
Humanoid.AutoRotate = false
ToggleStun(1.1)
wait(0.55)
Humanoid.AutoRotate = true
end
end
end
end)
the entire script worked and i just wanted to enhance it, by the way.
the script makes a region3, then finds all the parts within the region3, finds their upper face, then gets the closest point to you, then if the point is close enough, your character will climb the part. Everything worked but if there were 2 parts on top of each other it would randomly pick the point, and i want to make it so that it doesnt pick it randomly but rather picks the highest point.