--- LocalScript --- local PS = game:GetService("Players") local player = PS.LocalPlayer local mouse = player:GetMouse() local tool = script.Parent local heal = tool:WaitForChild("Heal") local highlights = {} -- Table to store the selection box instances local beam = nil -- Initialize the beam variable local currentTarget = nil -- Track the current player being hovered over local QuantityLabel = player.PlayerGui:WaitForChild("BackpackGui").Frame.quantityLabel tool.Equipped:Connect(function() -- Create selection boxes for all players for _, v in ipairs(PS:GetPlayers()) do if v ~= player then local char = v.Character if char and char:IsA("Model") then local charPart = char if charPart then local highlight = Instance.new("SelectionBox") highlight.Color3 = Color3.fromRGB(0, 249, 0) highlight.LineThickness = 0.1 highlight.Adornee = charPart highlight.Parent = charPart highlights[v] = highlight end end end end if not beam then beam = Instance.new("Beam") beam.Color = ColorSequence.new(Color3.fromRGB(0, 249, 0)) -- Set the beam color to green beam.Parent = workspace end mouse.Move:Connect(function() local targetPlayer = nil -- Check if the mouse is hovering over any player's character for _, v in ipairs(PS:GetPlayers()) do if v ~= player then local char = v.Character if char and char:IsA("Model") then local charPart = char:FindFirstChild("HumanoidRootPart") if charPart then local mouseHit = mouse.Hit.p local charPos = charPart.Position local distance = (mouseHit - charPos).Magnitude -- If the mouse is within a certain distance of the player's character, consider it a hover if distance <= 5 then targetPlayer = v break end end end end end if targetPlayer ~= currentTarget then -- Remove the beam if a new target is being hovered if beam then if beam.Attachment0 then beam.Attachment0:Destroy() end if beam.Attachment1 then beam.Attachment1:Destroy() end end if targetPlayer then -- Create and attach an attachment to the player's and the closest player's root parts local attachment0 = Instance.new("Attachment") attachment0.Parent = player.Character.HumanoidRootPart local attachment1 = Instance.new("Attachment") attachment1.Parent = targetPlayer.Character.HumanoidRootPart -- Set the Attachments as the end points of the beam if beam then beam.Attachment0 = attachment0 beam.Attachment1 = attachment1 end end currentTarget = targetPlayer end end) end) tool.Unequipped:Connect(function() -- Remove selection boxes when unequipping the tool for _, highlight in pairs(highlights) do highlight:Destroy() end highlights = {} -- Remove the beam attachments and destroy the beam when unequipping the tool if beam then if beam.Attachment0 then beam.Attachment0:Destroy() end if beam.Attachment1 then beam.Attachment1:Destroy() end beam:Destroy() beam = nil end currentTarget = nil end) tool.AncestryChanged:Connect(function(_, parent) -- Remove selection boxes and the beam when the tool is destroyed if not parent then for _, highlight in pairs(highlights) do highlight:Destroy() end highlights = {} if beam then if beam.Attachment0 then beam.Attachment0:Destroy() end if beam.Attachment1 then beam.Attachment1:Destroy() end beam:Destroy() beam = nil end currentTarget = nil end end) tool.Activated:Connect(function() if currentTarget then heal:FireServer(currentTarget) else -- If no other player is targeted by the mouse hover, heal the player using the tool heal:FireServer(player) if tool:WaitForChild("stacks").Value == 0 then QuantityLabel.Visible = false end end end) tool:WaitForChild("stacks").Changed:Connect(function(Value) QuantityLabel.Text = "Quantity: "..Value end) QuantityLabel.Text = "Quantity: "..tool.stacks.Value tool.Equipped:Connect(function() QuantityLabel.Visible = true end) tool.Unequipped:Connect(function() QuantityLabel.Visible = false end) --- Script --- local tool = script.Parent local heal = tool:WaitForChild("Heal") local remainingUses = 3 -- Variable to track the remaining uses local RunService = game:GetService("RunService") local function playHealEffect(character) local core = game.ReplicatedStorage:FindFirstChild("healingcore") -- Assuming the part is in ReplicatedStorage if core then local rootPart = character:FindFirstChild("HumanoidRootPart") if rootPart then core = core:Clone() core.Parent = rootPart core.CFrame = rootPart.CFrame -- Set the initial CFrame to match the HumanoidRootPart local weld = Instance.new("WeldConstraint") weld.Parent = core weld.Part0 = core weld.Part1 = rootPart wait(2) -- Wait for 2 seconds weld:Destroy() -- Remove the WeldConstraint core:Destroy() -- Destroy the part after 2 seconds end end end heal.OnServerEvent:Connect(function(player, target) local char = target.Character local hum = char:WaitForChild("Humanoid") if hum and hum.Health < hum.MaxHealth and remainingUses > 0 then hum.Health += 50 remainingUses -= 1 script.Parent.Sound.Playing = true playHealEffect(char) -- Call the function to play the heal effect if remainingUses <= 0 then tool.stacks.Value -= 1 if tool.stacks.Value == 0 then player.Character.Humanoid:UnequipTools() wait(0.0000000000000000001) tool:Destroy() end end end end)