local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local waitTime = 0.2
local enabled = false
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.H then
enabled = not enabled
end
end)
local function grabTop(model)
local highest = nil
local highestY = -math.huge
for _, obj in ipairs(model:GetDescendants()) do
if obj:IsA("BasePart") then
if obj.Position.Y > highestY then
highestY = obj.Position.Y
highest = obj
end
end
end
return highest
end
local function getModel(excludeModel)
local character = player.Character
if not character then return nil end
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return nil end
local closestModel = nil
local closestPart = nil
local shortestDistance = math.huge
for _, model in ipairs(workspace.Blocks:GetChildren()) do
if model:IsA("Model") then
if model ~= excludeModel then
local part = grabTop(model)
if part then
local distance = (hrp.Position - part.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
closestModel = model
closestPart = part
end
end
end
end
end
return closestModel, closestPart
end
local function getArea()
local character = player.Character
if not character then return nil end
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return nil end
local ray = Ray.new(hrp.Position, Vector3.new(0, -6, 0)) -- shut up. I know. >;c
local checked = workspace:FindPartOnRay(ray, character)
if checked then
local model = checked:FindFirstAncestorOfClass("Model")
if model then
return model
end
end
return nil
end
task.spawn(function()
while true do
if enabled then
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local currentModel = getArea()
local _, targetPart = getModel(currentModel)
if targetPart then
hrp.CFrame = targetPart.CFrame + Vector3.new(0, 3, 0)
end
end
task.wait(waitTime) -- Why make this a local when its literally called once? I dunno its easier for users.
end
end)
Comments
No comments yet
Be the first to share your thoughts!