here server script in tool too
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HealEvent = ReplicatedStorage:WaitForChild("Heal")
HealEvent.OnServerEvent:Connect(function(player, sentTool)
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and humanoid.Health < humanoid.MaxHealth then
humanoid.Health = math.min(humanoid.Health + 10, humanoid.MaxHealth)
if sentTool and sentTool:IsDescendantOf(character) then
sentTool:Destroy()
end
end
end)
here local in tool
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse
local holding = false
local HOLD_TIME = 2
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HealEvent = ReplicatedStorage:WaitForChild("Heal")
local TweenService = game:GetService("TweenService")
local barGui = player:WaitForChild("PlayerGui"):WaitForChild("UsingBar")
local bar = barGui:WaitForChild("BarBackground"):WaitForChild("Bar")
local animation = tool:WaitForChild("BandageUse")
local animator = nil
local animTrack = nil
local function resetBar()
bar.Size = UDim2.new(-0.007, 1, 1, 0)
end
local function hideGui()
barGui.Enabled = false
resetBar()
end
local function startTween()
bar.Size = UDim2.new(-0.007, 1, 1, 0)
local goal = { Size = UDim2.new(0.993, 1, 1, 0) }
local tweenInfo = TweenInfo.new(HOLD_TIME, Enum.EasingStyle.Linear)
local tween = TweenService:Create(bar, tweenInfo, goal)
tween:Play()
return tween
end
local function playAnimation()
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
if not animator then
animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
animator = Instance.new("Animator")
animator.Parent = humanoid
end
end
animTrack = animator:LoadAnimation(animation)
animTrack:Play()
end
local function stopAnimation()
if animTrack then
animTrack:Stop()
animTrack:Destroy()
animTrack = nil
end
end
tool.Equipped:Connect(function()
mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
if holding then return end
holding = true
barGui.Enabled = true
startTween()
playAnimation()
local startTime = tick()
while holding do
if tick() - startTime >= HOLD_TIME then
-- Удержание завершено — хил через сервер
HealEvent:FireServer(tool)
stopAnimation()
hideGui()
holding = false
return
end
task.wait()
end
end)
mouse.Button1Up:Connect(function()
if holding then
holding = false
stopAnimation()
hideGui()
end
end)
end)
tool.Unequipped:Connect(function()
if holding then
holding = false
end
stopAnimation()
hideGui()
end)