wanted to make custom item ESP for my game, and cant understand why position of the frame is being dragged down from the object position, its like frame is under the object, even though i want it to be exactly where object is?
Here's my local script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local hud = player.PlayerGui:FindFirstChild("Hud")
if not hud then
hud = Instance.new("ScreenGui")
hud.Name = "Hud"
hud.Parent = player.PlayerGui
end
local esp = hud:FindFirstChild("ESP")
if not esp then
esp = Instance.new("Frame")
esp.Name = "ESP"
esp.Size = UDim2.new(1, 0, 1, 0)
esp.BackgroundTransparency = 1
esp.Parent = hud
end
local frame : Frame = esp:FindFirstChild("Frame")
if not frame then
frame = Instance.new("Frame")
frame.Name = "Frame"
frame.Size = UDim2.new(0, 50, 0, 50)
frame.BackgroundTransparency = 1
frame.Visible = false
frame.AnchorPoint = Vector2.new(.5, .5)
frame.Parent = esp
end
local target = game.Workspace:FindFirstChild('items'):GetChildren()[7]
RunService.RenderStepped:Connect(function()
if target and frame then
local targetPos
if target:IsA("Model") then
targetPos = target.PrimaryPart and target.PrimaryPart.Position or target:GetBoundingBox().Position
elseif target:IsA("BasePart") then
targetPos = target.Position
end
if targetPos then
local screenPos, onScreen = camera:WorldToViewportPoint(targetPos)
if onScreen and screenPos.Z > 0 then
frame.Position = UDim2.fromOffset(screenPos.X, screenPos.Y)
frame.Visible = true
else
frame.Visible = false
end
else
frame.Visible = false
end
end
end)