Kenken_I

Untitled

May 3rd, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. --// SERVICES
  2. local Players = game:GetService("Players")
  3. local RunService = game:GetService("RunService")
  4. local LocalPlayer = Players.LocalPlayer
  5.  
  6. --// SETTINGS
  7. local MAX_REACH = 14
  8. local MIN_REACH = 14
  9. local DETECTION_RANGE = 21
  10. local CLOSE_HIT = 9
  11. local PREDICTION = 0.18
  12. local FIRETOUCH_DELAY = 0
  13. local JUMP_STATES = {
  14. [Enum.HumanoidStateType.Jumping] = true,
  15. [Enum.HumanoidStateType.Freefall] = true
  16. }
  17.  
  18. --// VARIABLES
  19. local equipped = false
  20. local tool, bubble = nil, nil
  21. local hue = 0
  22. local heartbeatConnection
  23.  
  24. --// FUNCTIONS
  25.  
  26. -- Create visual bubble
  27. local function createBubble()
  28. local part = Instance.new("Part")
  29. part.Name = "SafeReachBubble"
  30. part.Anchored = true
  31. part.CanCollide = false
  32. part.CastShadow = false
  33. part.Shape = Enum.PartType.Ball
  34. part.Material = Enum.Material.ForceField
  35. part.Transparency = 0.2
  36. part.Color = Color3.fromHSV(0, 1, 1)
  37. part.Size = Vector3.new(MAX_REACH * 2, MAX_REACH * 2, MAX_REACH * 2)
  38. part.Parent = LocalPlayer.Character
  39. return part
  40. end
  41.  
  42. -- Check visibility with raycasting
  43. local function isClear(origin, targetPos, targetChar)
  44. local dir = targetPos - origin
  45. local params = RaycastParams.new()
  46. params.FilterType = Enum.RaycastFilterType.Whitelist
  47. params.FilterDescendantsInstances = { targetChar }
  48. params.IgnoreWater = true
  49.  
  50. local result = workspace:Raycast(origin, dir, params)
  51. return result and result.Instance and result.Instance:IsDescendantOf(targetChar)
  52. end
  53.  
  54. -- Fire simulated touch
  55. local function touchCharacter(char, fromPos)
  56. local hrp = char:FindFirstChild("HumanoidRootPart")
  57. local handle = tool and tool:FindFirstChild("Handle")
  58. if not handle or not hrp then return end
  59.  
  60. local distance = (fromPos - hrp.Position).Magnitude
  61. if distance > 8.9 then return end
  62.  
  63. for _, part in ipairs(char:GetChildren()) do
  64. if part:IsA("BasePart") then
  65. task.delay(FIRETOUCH_DELAY, function()
  66. firetouchinterest(handle, part, 0)
  67. firetouchinterest(handle, part, 1)
  68. end)
  69. end
  70. end
  71. end
  72.  
  73. -- Adjust reach based on movement
  74. local function getAdjustedReach(player, hrp, humanoid)
  75. if JUMP_STATES[humanoid:GetState()] then
  76. return MIN_REACH
  77. end
  78.  
  79. local moveDir = humanoid.MoveDirection
  80. local toPlayer = (LocalPlayer.Character.HumanoidRootPart.Position - hrp.Position).Unit
  81.  
  82. if moveDir.Magnitude > 0.1 and moveDir:Dot(-toPlayer) > 0.5 then
  83. return MIN_REACH
  84. end
  85.  
  86. return MAX_REACH
  87. end
  88.  
  89. -- Stop main loop
  90. local function stopLoop()
  91. if heartbeatConnection then
  92. heartbeatConnection:Disconnect()
  93. heartbeatConnection = nil
  94. end
  95. end
  96.  
  97. -- When tool is equipped
  98. local function onEquipped()
  99. equipped = true
  100. tool = LocalPlayer.Character and LocalPlayer.Character:FindFirstChildOfClass("Tool")
  101. if not tool then return end
  102.  
  103. if not bubble then
  104. bubble = createBubble()
  105. end
  106.  
  107. stopLoop()
  108. heartbeatConnection = RunService.Heartbeat:Connect(function()
  109. local char = LocalPlayer.Character
  110. local hrp = char and char:FindFirstChild("HumanoidRootPart")
  111. if not equipped or not tool or not hrp then return end
  112.  
  113. hue = (hue + 0.01) % 1
  114. if bubble then
  115. bubble.Position = hrp.Position
  116. bubble.Color = Color3.fromHSV(hue, 1, 1)
  117. end
  118.  
  119. for _, target in ipairs(Players:GetPlayers()) do
  120. if target ~= LocalPlayer and target.Character then
  121. local tChar = target.Character
  122. local tHRP = tChar:FindFirstChild("HumanoidRootPart")
  123. local humanoid = tChar:FindFirstChildOfClass("Humanoid")
  124.  
  125. if tHRP and humanoid and humanoid.Health > 0 then
  126. local rawDistance = (hrp.Position - tHRP.Position).Magnitude
  127. -- Skip players who are farther than 9.3 studs
  128. if rawDistance > 9.3 then continue end
  129.  
  130. if rawDistance <= DETECTION_RANGE then
  131. local reach = getAdjustedReach(target, tHRP, humanoid)
  132. if bubble then
  133. bubble.Size = Vector3.new(reach * 2, reach * 2, reach * 2)
  134. end
  135.  
  136. if rawDistance <= reach then
  137. if rawDistance <= CLOSE_HIT then
  138. touchCharacter(tChar, hrp.Position)
  139. else
  140. local predicted = tHRP.Position + tHRP.Velocity * PREDICTION
  141. if isClear(hrp.Position, predicted, tChar) then
  142. touchCharacter(tChar, hrp.Position)
  143. elseif isClear(hrp.Position, tHRP.Position, tChar) then
  144. touchCharacter(tChar, hrp.Position)
  145. end
  146. end
  147. end
  148. end
  149. end
  150. end
  151. end
  152. end)
  153. end
  154.  
  155. -- When tool is unequipped
  156. local function onUnequipped()
  157. equipped = false
  158. stopLoop()
  159. if bubble then
  160. bubble:Destroy()
  161. bubble = nil
  162. end
  163. end
  164.  
  165. -- Set up character on spawn
  166. local function setupCharacter(char)
  167. local humanoid = char:FindFirstChildOfClass("Humanoid")
  168. local backpack = LocalPlayer:FindFirstChild("Backpack")
  169. if humanoid and backpack then
  170. local toolInBackpack = backpack:FindFirstChildOfClass("Tool")
  171. if toolInBackpack then
  172. humanoid:EquipTool(toolInBackpack)
  173. end
  174. end
  175.  
  176. char.ChildAdded:Connect(function(child)
  177. if child:IsA("Tool") then
  178. child.Equipped:Connect(onEquipped)
  179. child.Unequipped:Connect(onUnequipped)
  180. end
  181. end)
  182.  
  183. for _, child in ipairs(char:GetChildren()) do
  184. if child:IsA("Tool") then
  185. child.Equipped:Connect(onEquipped)
  186. child.Unequipped:Connect(onUnequipped)
  187. end
  188. end
  189. end
  190.  
  191. -- INIT
  192. if LocalPlayer.Character then
  193. setupCharacter(LocalPlayer.Character)
  194. end
  195.  
  196. LocalPlayer.CharacterAdded:Connect(setupCharacter)
Advertisement
Add Comment
Please, Sign In to add comment