Help with the bandage system

so when i hold mouse and than leave it it not heals but when i click many times its heals+

script:

local Tool = script.Parent

repeat wait() until Tool.Parent:IsA("Model")

local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local char = Tool.Parent
local hum = char:WaitForChild("Humanoid")
local UseAnim = hum:LoadAnimation(Tool:WaitForChild("Animations").wrap)
local idle = hum:LoadAnimation(Tool:WaitForChild("Animations").idle)

Equipped = false
Used = false
Holding = false

function Equip()
	Equipped = true
	idle:Play()
	Tool:WaitForChild("Handle").Unequip:Stop()
	Tool:WaitForChild("Handle").Equip:Play()
end

function UnEquip()
	Equipped = false
	Tool:WaitForChild("Handle").Equip:Stop()
	Tool:WaitForChild("Handle").Unequip:Stop()
	Tool:WaitForChild("Handle").Wrap:Stop()
	idle:Stop()
	UseAnim:Stop()
end

uis.InputBegan:Connect(function(input)
	if Equipped == true and char and hum and Holding == false and player and Used == false then
		if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
			Holding = true
			Used = true
			Tool:WaitForChild("Handle").Equip:Stop()
			Tool:WaitForChild("Handle").Wrap:Play()
			local HealTime = 3.40
			idle:Stop()
			UseAnim:Play()
			hum.WalkSpeed = 2

			if Equipped and Holding then
				if Holding then
					task.wait(HealTime)
					if Holding then
						Tool:WaitForChild("EZ"):FireServer()
						hum.WalkSpeed = 16
					end
				end
			end
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if Equipped == true and char and hum and Holding == true and player then
		if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
			Holding = false
			UseAnim:Stop()
			hum.WalkSpeed = 16
			Tool:WaitForChild("Handle").Wrap:Stop()
			if script.Parent then
				Used = false
				Holding = false
			end
		end
	end
end)

Tool.Equipped:Connect(Equip)
Tool.Unequipped:Connect(UnEquip)
1 Like

This is only running when this function runs,
Try taking it out and putting it in a while loop

so like

while Equipped and Holding do 
   -- other code here
end
1 Like

nope still same it not working

Any errors?

Other than that I cant really help, srry

yes no errors no problem btw thanks for help

1 Like

If I understand correctly, you want to make it heals the player when holding the mousebutton1 right? If so, then you can just use:

coroutine.wrap(function()
	 while using do
		wait(1)
		print("IsHealing")
       -- Your code to heal the player
	end
end)()

Inside the UIS.InputBegan function

but if you want to heal the player when they stop holding the mousebutton1 then you can use a variable to detect if the player is not already holding, then holding = true in the UIS.InputBegan function, and in the InputEnded function you detect if the player is holding, and then holding = false and heals the player.

btw, you dont need to check if the player is “Holding” multiple times, as you already did it in “if Equipped and Holding then”.

1 Like

yea i did that

i just did your solituon and it still did not work
here video:

What are you referring to? The part of healing the player or the animation? Please specify

it plays an animation while player holding the mouse if player leaves mouse it will not gona heal it and animation will stop

So you want to make it like if the player stops holding it will “cancel” the healing?

yes thats what i wanted (voicesinmyhead)

You can define a new variable: “Healed”

UIS.InputBegan
While using the slowly increases the hp of the player, if some seconds passed and player’s health is full then Healed = true and stops the animation & using = false

UIS.InputEnded
If not Healed then stops healing the player and Animation:Stop()

2 Likes