Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LocalScript inside StarterGui (example: StarterGui > ScreenGui > LocalScript)
- -- Services
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local player = Players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- -- Create ScreenGui that survives death
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "PersistentGUI"
- screenGui.ResetOnSpawn = false
- screenGui.Parent = playerGui
- -- Create the frame (bigger)
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 300, 0, 280) -- bigger size
- frame.Position = UDim2.new(0.5, -150, 0.5, -140)
- frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- frame.BorderSizePixel = 0
- frame.Active = true
- frame.Draggable = true
- frame.Parent = screenGui
- -- Rounded corners
- local corner = Instance.new("UICorner")
- corner.CornerRadius = UDim.new(0, 14)
- corner.Parent = frame
- -- White outline around frame
- local stroke = Instance.new("UIStroke")
- stroke.Thickness = 3
- stroke.Color = Color3.fromRGB(255, 255, 255)
- stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
- stroke.Parent = frame
- -- Title text
- local title = Instance.new("TextLabel")
- title.Size = UDim2.new(1, -20, 0, 40) -- bigger height
- title.Position = UDim2.new(0, 10, 0, 10)
- title.BackgroundTransparency = 1
- title.Text = "Attach GUI v3.1"
- title.TextColor3 = Color3.fromRGB(255, 255, 255)
- title.Font = Enum.Font.GothamBold
- title.TextScaled = true
- title.Parent = frame
- -- TextBox (bigger)
- local textbox = Instance.new("TextBox")
- textbox.Size = UDim2.new(1, -20, 0, 50)
- textbox.Position = UDim2.new(0, 10, 0, 60)
- textbox.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- textbox.Text = ""
- textbox.TextColor3 = Color3.fromRGB(0, 0, 0)
- textbox.PlaceholderText = "Enter player name..."
- textbox.Font = Enum.Font.Gotham
- textbox.TextSize = 20
- textbox.ClearTextOnFocus = false
- textbox.Parent = frame
- local textboxCorner = Instance.new("UICorner")
- textboxCorner.CornerRadius = UDim.new(0, 10)
- textboxCorner.Parent = textbox
- -- Attach button (bigger)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(1, -20, 0, 50)
- button.Position = UDim2.new(0, 10, 0, 120)
- button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- button.Text = "Attach Off"
- button.TextColor3 = Color3.fromRGB(0, 0, 0)
- button.Font = Enum.Font.GothamBold
- button.TextSize = 20
- button.Parent = frame
- local buttonCorner = Instance.new("UICorner")
- buttonCorner.CornerRadius = UDim.new(0, 10)
- buttonCorner.Parent = button
- -- Attach logic
- local isAttached = false
- local targetPlr = nil
- local connection
- -- Find target by username/display name
- local function findTarget(nameInput)
- nameInput = string.lower(nameInput)
- for _, plr in pairs(Players:GetPlayers()) do
- if string.find(string.lower(plr.Name), nameInput)
- or string.find(string.lower(plr.DisplayName), nameInput) then
- return plr
- end
- end
- return nil
- end
- -- Start attach loop
- local function startAttach()
- if connection then connection:Disconnect() end
- connection = RunService.Heartbeat:Connect(function()
- local myChar = player.Character
- local targetChar = targetPlr and targetPlr.Character
- if myChar and myChar:FindFirstChild("HumanoidRootPart")
- and targetChar and targetChar:FindFirstChild("HumanoidRootPart") then
- local myRoot = myChar.HumanoidRootPart
- local targetRoot = targetChar.HumanoidRootPart
- myRoot.CFrame = targetRoot.CFrame * CFrame.new(0, 0, 1) -- stay 1 stud behind
- end
- end)
- -- Re-attach after YOU respawn
- player.CharacterAdded:Connect(function()
- if isAttached then
- task.wait(1)
- startAttach()
- end
- end)
- -- Re-attach after TARGET respawns
- if targetPlr then
- targetPlr.CharacterAdded:Connect(function()
- if isAttached then
- task.wait(1)
- startAttach()
- end
- end)
- end
- end
- -- Button toggle
- button.MouseButton1Click:Connect(function()
- if isAttached then
- isAttached = false
- button.Text = "Attach Off"
- button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- if connection then
- connection:Disconnect()
- connection = nil
- end
- targetPlr = nil
- else
- local plr = findTarget(textbox.Text)
- if plr then
- isAttached = true
- targetPlr = plr
- button.Text = "Attach On"
- button.BackgroundColor3 = Color3.fromRGB(0, 200, 0)
- startAttach()
- else
- button.Text = "Player not found"
- task.wait(1.2)
- button.Text = "Attach Off"
- end
- end
- end)
Add Comment
Please, Sign In to add comment