Only 1 button work, the other one does not. (Script conflict?)

Hello forum, today i have a gui that i wanted to use for a bandage tool that can help me heal my limbs by clicking on a button. The problem is, in the frame, only 1 button with the script work, the remaining is completely useless for some reason. I tried editing it after making it multiple time but still no progress. Any help is appreciated! (No error).

The button location (i only make 2 because i already knew that the other won’t work)
Screenshot 2024-06-25 103235

The button script:

print("Button script running")  -- Ensure this script runs

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local folder = char:WaitForChild("HealingEvent")
local button = script.Parent

-- Assuming this script is placed inside the Frame that contains the buttons
local frame = script.Parent.Parent
local buttons = frame:GetChildren()

for _, button in ipairs(buttons) do
	if button:IsA("TextButton") then -- Ensure that the object is a button
		local eventName = button.Name -- Assuming each button's name corresponds to an event in the folder
		print("Found button:", button.Name)  -- Ensure the button is found (optional)

		button.MouseButton1Click:Connect(function()
			print("Button clicked:", button.Name)  -- Ensure button click is detected
			local event = folder:FindFirstChild(eventName)
			if event and event:IsA("RemoteEvent") then
				print("Firing event:", eventName)  -- Ensure event firing is attempted
				event:FireServer()
				frame:Destroy() -- Hide the frame instead of destroying it
			else
				warn("Event " .. eventName .. " not found or is not a RemoteEvent")
			end
		end)
	end
end

The Healing script inside the tool:

local tool = script.Parent
local toolOwner = tool.Parent:IsA("Model") and tool.Parent or tool.Parent:IsA("Backpack") and tool.Parent.Parent.Character

if tool.Parent:IsA("Model") then
	toolOwner = tool.Parent
elseif tool.Parent:IsA("Backpack") then
	toolOwner = tool.Parent.Parent.Character
else
	warn("Unexpected tool parent type: " .. tostring(tool.Parent.ClassName))
	return
end

local plr = game.Players:GetPlayerFromCharacter(toolOwner)
if not plr then
	warn("Player not found from character")
	return
end

local mainchar = plr.Character or plr.CharacterAdded:Wait()
local mainHum = mainchar:WaitForChild("Humanoid")
local healAnim1 = tool:WaitForChild("LArmHeal")
local healAnim2 = tool:WaitForChild("RArmHeal")
local eventFolder = mainchar:WaitForChild("HealingEvent")
local event = eventFolder:WaitForChild("LArm")
local event2 = eventFolder:WaitForChild("RArm")
local deb = false
local maxHealth = 100 -- Change to your max health
local LArm = mainchar:WaitForChild("Left Arm")
local RArm = mainchar:WaitForChild("Right Arm")

-- Ensure the LArm and RArm have the Health attribute set
if not LArm:GetAttribute("Health") then
	LArm:SetAttribute("Health", 100)
end

if not RArm:GetAttribute("Health") then
	RArm:SetAttribute("Health", 100)
end

local LArmoriginalHP = LArm:GetAttribute("Health")
local RArmoriginalHP = RArm:GetAttribute("Health")

event.OnServerEvent:Connect(function()
	print("LArm event triggered")  -- Ensure LArm event is triggered
	if not deb then
		deb = true
		if mainHum.Health < maxHealth or mainHum.Health == maxHealth - 1 then
			local healTrack = mainHum:LoadAnimation(healAnim1)
			print("Healing LArm")  -- Ensure healing animation starts for LArm
			healTrack:Play()
			healTrack.Stopped:Wait()
			local currentLArmHP = LArm:GetAttribute("Health")
			if currentLArmHP then
				LArm:SetAttribute("Health", currentLArmHP + 10)
			else
				warn("LArm Health attribute is nil")
			end
			mainHum.Health = math.min(maxHealth, mainHum.Health + 25)
			tool:Destroy()
		end
		wait(10)
		deb = false -- Cooldown
	end
end)

event2.OnServerEvent:Connect(function()
	print("RArm event triggered")  -- Ensure RArm event is triggered
	if not deb then
		deb = true
		if mainHum.Health < maxHealth or mainHum.Health == maxHealth - 1 then
			local healTrack = mainHum:LoadAnimation(healAnim2)
			print("Healing RArm")  -- Ensure healing animation starts for RArm
			healTrack:Play()
			healTrack.Stopped:Wait()
			local currentRArmHP = RArm:GetAttribute("Health")
			if currentRArmHP then
				RArm:SetAttribute("Health", currentRArmHP + 10)
			else
				warn("RArm Health attribute is nil")
			end
			mainHum.Health = math.min(maxHealth, mainHum.Health + 25)
			tool:Destroy()
		end
		wait(10)
		deb = false -- Cooldown
	end
end)

mainHum:GetPropertyChangedSignal("Health"):Connect(function()
	LArmoriginalHP = LArm:GetAttribute("Health")
	RArmoriginalHP = RArm:GetAttribute("Health")
	if LArmoriginalHP > 100 then
		LArm:SetAttribute("Health", 100)
	elseif RArmoriginalHP > 100 then
		RArm:SetAttribute("Health", 100)
	end
end)
1 Like

At a glance, frame:Destroy() will destroy another button too.

1 Like

hey there, so quick explaination: the frame is only destroyed once the button is clicked, anything happen before that does not affect the frame.

Oh I understood now. Can you share me the output of the dev console when you click the right button?(if nothing is printed, could you please share me properties of the Rarm button!)

2 Likes

Ok i firgured it out, apparently i used Button.Name which the script get confused, i changed it to “RArm” and now it worked fine. Regardless, thank you for your help Nick!

2 Likes

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