Rojhann10

Untitled

Sep 3rd, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. -- LocalScript inside StarterGui (example: StarterGui > ScreenGui > LocalScript)
  2.  
  3. -- Services
  4. local Players = game:GetService("Players")
  5. local RunService = game:GetService("RunService")
  6. local player = Players.LocalPlayer
  7. local playerGui = player:WaitForChild("PlayerGui")
  8.  
  9. -- Create ScreenGui that survives death
  10. local screenGui = Instance.new("ScreenGui")
  11. screenGui.Name = "PersistentGUI"
  12. screenGui.ResetOnSpawn = false
  13. screenGui.Parent = playerGui
  14.  
  15. -- Create the frame (bigger)
  16. local frame = Instance.new("Frame")
  17. frame.Size = UDim2.new(0, 300, 0, 280) -- bigger size
  18. frame.Position = UDim2.new(0.5, -150, 0.5, -140)
  19. frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  20. frame.BorderSizePixel = 0
  21. frame.Active = true
  22. frame.Draggable = true
  23. frame.Parent = screenGui
  24.  
  25. -- Rounded corners
  26. local corner = Instance.new("UICorner")
  27. corner.CornerRadius = UDim.new(0, 14)
  28. corner.Parent = frame
  29.  
  30. -- White outline around frame
  31. local stroke = Instance.new("UIStroke")
  32. stroke.Thickness = 3
  33. stroke.Color = Color3.fromRGB(255, 255, 255)
  34. stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
  35. stroke.Parent = frame
  36.  
  37. -- Title text
  38. local title = Instance.new("TextLabel")
  39. title.Size = UDim2.new(1, -20, 0, 40) -- bigger height
  40. title.Position = UDim2.new(0, 10, 0, 10)
  41. title.BackgroundTransparency = 1
  42. title.Text = "Attach GUI v3.1"
  43. title.TextColor3 = Color3.fromRGB(255, 255, 255)
  44. title.Font = Enum.Font.GothamBold
  45. title.TextScaled = true
  46. title.Parent = frame
  47.  
  48. -- TextBox (bigger)
  49. local textbox = Instance.new("TextBox")
  50. textbox.Size = UDim2.new(1, -20, 0, 50)
  51. textbox.Position = UDim2.new(0, 10, 0, 60)
  52. textbox.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  53. textbox.Text = ""
  54. textbox.TextColor3 = Color3.fromRGB(0, 0, 0)
  55. textbox.PlaceholderText = "Enter player name..."
  56. textbox.Font = Enum.Font.Gotham
  57. textbox.TextSize = 20
  58. textbox.ClearTextOnFocus = false
  59. textbox.Parent = frame
  60.  
  61. local textboxCorner = Instance.new("UICorner")
  62. textboxCorner.CornerRadius = UDim.new(0, 10)
  63. textboxCorner.Parent = textbox
  64.  
  65. -- Attach button (bigger)
  66. local button = Instance.new("TextButton")
  67. button.Size = UDim2.new(1, -20, 0, 50)
  68. button.Position = UDim2.new(0, 10, 0, 120)
  69. button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  70. button.Text = "Attach Off"
  71. button.TextColor3 = Color3.fromRGB(0, 0, 0)
  72. button.Font = Enum.Font.GothamBold
  73. button.TextSize = 20
  74. button.Parent = frame
  75.  
  76. local buttonCorner = Instance.new("UICorner")
  77. buttonCorner.CornerRadius = UDim.new(0, 10)
  78. buttonCorner.Parent = button
  79.  
  80. -- Attach logic
  81. local isAttached = false
  82. local targetPlr = nil
  83. local connection
  84.  
  85. -- Find target by username/display name
  86. local function findTarget(nameInput)
  87. nameInput = string.lower(nameInput)
  88. for _, plr in pairs(Players:GetPlayers()) do
  89. if string.find(string.lower(plr.Name), nameInput)
  90. or string.find(string.lower(plr.DisplayName), nameInput) then
  91. return plr
  92. end
  93. end
  94. return nil
  95. end
  96.  
  97. -- Start attach loop
  98. local function startAttach()
  99. if connection then connection:Disconnect() end
  100.  
  101. connection = RunService.Heartbeat:Connect(function()
  102. local myChar = player.Character
  103. local targetChar = targetPlr and targetPlr.Character
  104.  
  105. if myChar and myChar:FindFirstChild("HumanoidRootPart")
  106. and targetChar and targetChar:FindFirstChild("HumanoidRootPart") then
  107. local myRoot = myChar.HumanoidRootPart
  108. local targetRoot = targetChar.HumanoidRootPart
  109. myRoot.CFrame = targetRoot.CFrame * CFrame.new(0, 0, 1) -- stay 1 stud behind
  110. end
  111. end)
  112.  
  113. -- Re-attach after YOU respawn
  114. player.CharacterAdded:Connect(function()
  115. if isAttached then
  116. task.wait(1)
  117. startAttach()
  118. end
  119. end)
  120.  
  121. -- Re-attach after TARGET respawns
  122. if targetPlr then
  123. targetPlr.CharacterAdded:Connect(function()
  124. if isAttached then
  125. task.wait(1)
  126. startAttach()
  127. end
  128. end)
  129. end
  130. end
  131.  
  132. -- Button toggle
  133. button.MouseButton1Click:Connect(function()
  134. if isAttached then
  135. isAttached = false
  136. button.Text = "Attach Off"
  137. button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  138. if connection then
  139. connection:Disconnect()
  140. connection = nil
  141. end
  142. targetPlr = nil
  143. else
  144. local plr = findTarget(textbox.Text)
  145. if plr then
  146. isAttached = true
  147. targetPlr = plr
  148. button.Text = "Attach On"
  149. button.BackgroundColor3 = Color3.fromRGB(0, 200, 0)
  150. startAttach()
  151. else
  152. button.Text = "Player not found"
  153. task.wait(1.2)
  154. button.Text = "Attach Off"
  155. end
  156. end
  157. end)
Advertisement
Add Comment
Please, Sign In to add comment