Advertisement
KenshiOfficial

Fortune fighters script

Oct 4th, 2024
3,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. -- Create a function to generate the GUI
  2. local function createGUI()
  3. local gui = Instance.new("ScreenGui")
  4. gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  5. gui.DisplayOrder = 10
  6.  
  7. -- Frame to hold the buttons
  8. local frame = Instance.new("Frame")
  9. frame.Size = UDim2.new(0, 200, 0, 100)
  10. frame.Position = UDim2.new(1, -210, 0, 10) -- Upper-right corner
  11. frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  12. frame.BorderSizePixel = 2
  13. frame.Parent = gui
  14.  
  15. -- Button to start the script
  16. local startButton = Instance.new("TextButton")
  17. startButton.Size = UDim2.new(0, 80, 0, 30)
  18. startButton.Position = UDim2.new(0.1, 0, 0.1, 0)
  19. startButton.Text = "Start"
  20. startButton.Parent = frame
  21.  
  22. -- Button to stop the script
  23. local stopButton = Instance.new("TextButton")
  24. stopButton.Size = UDim2.new(0, 80, 0, 30)
  25. stopButton.Position = UDim2.new(0.1, 0, 0.5, 0)
  26. stopButton.Text = "Stop"
  27. stopButton.Parent = frame
  28.  
  29. -- Variables
  30. local player = game.Players.LocalPlayer
  31. local replicatedStorage = game:GetService("ReplicatedStorage")
  32. local punchHitEvent = replicatedStorage:WaitForChild("PunchHitEvent")
  33. local scriptRunning = false -- Controls whether the script is active
  34.  
  35. -- Function to find the closest player
  36. local function getClosestPlayer()
  37. local closestPlayer = nil
  38. local shortestDistance = math.huge
  39.  
  40. for _, otherPlayer in pairs(game.Players:GetPlayers()) do
  41. if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  42. local distance = (player.Character.HumanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).Magnitude
  43. if distance < shortestDistance then
  44. closestPlayer = otherPlayer
  45. shortestDistance = distance
  46. end
  47. end
  48. end
  49.  
  50. return closestPlayer
  51. end
  52.  
  53. -- Function to fire the PunchHitEvent on the closest player
  54. local function firePunchHitEvent()
  55. local closestPlayer = getClosestPlayer()
  56. if closestPlayer and closestPlayer.Character then
  57. local args = {
  58. [1] = closestPlayer.Character:FindFirstChild("Left Arm"),
  59. [2] = closestPlayer.Character.Humanoid,
  60. [3] = true
  61. }
  62. punchHitEvent:FireServer(unpack(args))
  63. end
  64. end
  65.  
  66. -- Function to run the loop that fires the event continuously
  67. local function startScript()
  68. scriptRunning = true
  69. while scriptRunning do
  70. firePunchHitEvent()
  71. task.wait(0.001) -- Wait for 1 millisecond
  72. end
  73. end
  74.  
  75. -- Button actions
  76. startButton.MouseButton1Click:Connect(function()
  77. if not scriptRunning then
  78. startScript()
  79. end
  80. end)
  81.  
  82. stopButton.MouseButton1Click:Connect(function()
  83. scriptRunning = false
  84. end)
  85. end
  86.  
  87. -- Connect the GUI creation to player character respawn
  88. game.Players.LocalPlayer.CharacterAdded:Connect(function()
  89. createGUI()
  90. end)
  91.  
  92. -- Initial call to create the GUI
  93. createGUI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement