Rojhann10

Untitled

Sep 6th, 2025
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 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, 340) -- taller to fit extra button
  18. frame.Position = UDim2.new(0.5, -150, 0.5, -170)
  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.2"
  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. -- Direction toggle button
  81. local directionButton = Instance.new("TextButton")
  82. directionButton.Size = UDim2.new(1, -20, 0, 50)
  83. directionButton.Position = UDim2.new(0, 10, 0, 180)
  84. directionButton.BackgroundColor3 = Color3.fromRGB(200, 200, 200)
  85. directionButton.Text = "Direction: Backward"
  86. directionButton.TextColor3 = Color3.fromRGB(0, 0, 0)
  87. directionButton.Font = Enum.Font.GothamBold
  88. directionButton.TextSize = 20
  89. directionButton.Parent = frame
  90.  
  91. local directionCorner = Instance.new("UICorner")
  92. directionCorner.CornerRadius = UDim.new(0, 10)
  93. directionCorner.Parent = directionButton
  94.  
  95. -- Attach logic
  96. local isAttached = false
  97. local targetPlr = nil
  98. local connection
  99. local attachForward = false -- false = backward, true = forward
  100.  
  101. -- Find target by username/display name
  102. local function findTarget(nameInput)
  103. nameInput = string.lower(nameInput)
  104. for _, plr in pairs(Players:GetPlayers()) do
  105. if string.find(string.lower(plr.Name), nameInput)
  106. or string.find(string.lower(plr.DisplayName), nameInput) then
  107. return plr
  108. end
  109. end
  110. return nil
  111. end
  112.  
  113. -- Start attach loop
  114. local function startAttach()
  115. if connection then connection:Disconnect() end
  116.  
  117. connection = RunService.Heartbeat:Connect(function()
  118. local myChar = player.Character
  119. local targetChar = targetPlr and targetPlr.Character
  120.  
  121. if myChar and myChar:FindFirstChild("HumanoidRootPart")
  122. and targetChar and targetChar:FindFirstChild("HumanoidRootPart") then
  123. local myRoot = myChar.HumanoidRootPart
  124. local targetRoot = targetChar.HumanoidRootPart
  125.  
  126. if attachForward then
  127. myRoot.CFrame = targetRoot.CFrame * CFrame.new(0, 0, -1) -- in front
  128. else
  129. myRoot.CFrame = targetRoot.CFrame * CFrame.new(0, 0, 1) -- behind
  130. end
  131. end
  132. end)
  133.  
  134. -- Re-attach after YOU respawn
  135. player.CharacterAdded:Connect(function()
  136. if isAttached then
  137. task.wait(1)
  138. startAttach()
  139. end
  140. end)
  141.  
  142. -- Re-attach after TARGET respawns
  143. if targetPlr then
  144. targetPlr.CharacterAdded:Connect(function()
  145. if isAttached then
  146. task.wait(1)
  147. startAttach()
  148. end
  149. end)
  150. end
  151. end
  152.  
  153. -- Button toggle
  154. button.MouseButton1Click:Connect(function()
  155. if isAttached then
  156. isAttached = false
  157. button.Text = "Attach Off"
  158. button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  159. if connection then
  160. connection:Disconnect()
  161. connection = nil
  162. end
  163. targetPlr = nil
  164. else
  165. local plr = findTarget(textbox.Text)
  166. if plr then
  167. isAttached = true
  168. targetPlr = plr
  169. button.Text = "Attach On"
  170. button.BackgroundColor3 = Color3.fromRGB(0, 200, 0)
  171. startAttach()
  172. else
  173. button.Text = "Player not found"
  174. task.wait(1.2)
  175. button.Text = "Attach Off"
  176. end
  177. end
  178. end)
  179.  
  180. -- Direction toggle
  181. directionButton.MouseButton1Click:Connect(function()
  182. attachForward = not attachForward
  183. if attachForward then
  184. directionButton.Text = "Direction: Forward"
  185. directionButton.BackgroundColor3 = Color3.fromRGB(0, 200, 200)
  186. else
  187. directionButton.Text = "Direction: Backward"
  188. directionButton.BackgroundColor3 = Color3.fromRGB(200, 200, 200)
  189. end
  190. end)
Advertisement
Add Comment
Please, Sign In to add comment