Bandage Problems

  1. What do you want to achieve?

I want to achieve the player heal from the tool and when the use time Is done, I want it to heal the player some way.

  1. What is the issue?

Whenever I click and wait a second, and when I hold and again wait a couple seconds, the player gets healed out of nowhere.

  1. What solutions have you tried so far?

I’ve tried using “using.Ended:Wait” but if you just click, It’ll just instantly heals you.

I honestly don’t know what to do so thats why I’m asking here.

The script:

local player = game:GetService("Players").LocalPlayer
local player_gui = player.PlayerGui
local starter_gui = game:GetService("StarterGui")
local char = workspace:WaitForChild(player.Name)
local hum = char:WaitForChild("Humanoid")
local torso = char:WaitForChild("Torso")
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local using_item_gui = script:WaitForChild("using_item_gui")
local using_value = script:WaitForChild("using")

local animations_folder = script.Parent.Animations
local equip_anim = animations_folder.equip
local idle_anim = animations_folder.idle
local using_anim = animations_folder.using

local equip = hum:LoadAnimation(equip_anim)
local idle = hum:LoadAnimation(idle_anim)
local using = hum:LoadAnimation(using_anim)

local tween_service = game:GetService("TweenService")
local uis = game:GetService("UserInputService")

local equipped = false
local can_use = true
local equip_time = 0.5
local cooldown = 0.5
local use_time = 4.75

local udim2_stuff = {

	goal = UDim2.new(1, 0, 1, 0),
	default = UDim2.new(0, 0, 0, 0)

}

tool.Equipped:Connect(function()

	starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	handle.equip:Play()
	equip:Play()
	idle:Play()

	task.wait(equip_time)

	equipped = true
	starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

end)

tool.Unequipped:Connect(function()

	if handle.equip.IsPlaying then
		handle.equip:Stop()
	end

	if equip.IsPlaying then
		equip:Stop()
	end

	idle:Stop()
	equipped = false

	if using_value.Value == true then
		using_value.Value = false
	end

end)

uis.InputBegan:Connect(function(input, isChatting) -- the issue is here

	if isChatting then
		return
	end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped and can_use then

		handle.using:Play()
		using:Play()
		using_value.Value = true
		--warn("Using "..tool.Name)
		starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

		local temporary_using_gui = using_item_gui:Clone()
		temporary_using_gui.Parent = player_gui
		temporary_using_gui.Frame.TextLabel.Text = "Healing."
		temporary_using_gui.Frame.Fill:TweenSize(udim2_stuff.goal, "Out", "Linear", use_time)

		task.wait(use_time)

		if equipped and using_value.Value == true then
			starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
			temporary_using_gui:Destroy()
			hum.Health += hum.Health * 1.5
			idle:Stop()
			using:Stop()
			can_use = false

			local heal_sound = script:FindFirstChild("healed"):Clone()
			heal_sound.Parent = torso
			heal_sound:Play()

			heal_sound.Ended:Wait()

			tool:Destroy()

		end
	end

end)

uis.InputEnded:Connect(function(input, isChatting)

	if isChatting then
		return
	end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped and can_use then

		handle.using:Stop()
		using:Stop()
		using_value.Value = false
		--warn("No longer using "..tool.Name)
		starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

		local temporary_using_gui = player_gui:FindFirstChild("using_item_gui")

		if temporary_using_gui then
			temporary_using_gui:Destroy()
		end

		can_use = false
		task.wait(cooldown)
		can_use = true

	end

end)

Sorry I forgot to put some screenshots on how it looks like. Here:
image

I don’t care on what solution or on how you code it. Do whatever you want with it and try to make it (i hope) work. Thanks!

1 Like