Heal script not work help pls

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)

Hello, can you provide more information about your problem:

  1. Where’s the problem: server or client.
  2. What’s the problem: GUI tweens, animation, healing function.
  3. I want to ask you to show me script output to manage the problem more clear.

But I already detected one bug. When you equip your tool you connect hold function, but when you unequip tool, you dont disconnect it. Your connection in stacking, means once per mouse Button1Down event you fire as many function as you equipped the tool. To fix it you need to store mouse Button1Down connection into a variable and once tool in equipped disconnect it.

my script 100% working i just stupid idiot, i set 10 health in explorer, i do damagepart and when i get damage heal worked but thanks for answer : D

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.