No Errors But Script Not Running

In this script in a button in my hotbar system, I put a print statement and it printed each time after each line but it doesn’t actually run.

script.Parent.MouseButton1Up:Connect(function()
	if script.Parent:GetAttribute("Equipped") == false then
		script.Parent.Aesthetics.Enabled = false
		game.TweenService:Create(script.Parent, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 87, 0, 87)}):Play()
		game.TweenService:Create(script.Parent.Outline, TweenInfo.new(0.1), {Transparency = 0}):Play()
		script.Parent:SetAttribute("Equipped", true)
		
		for _, Button in ipairs(script.Parent.Parent:GetChildren()) do
			if Button:IsA("ImageButton") then
				game.TweenService:Create(Button, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
				game.TweenService:Create(Button.Outline, TweenInfo.new(0.1), {Transparency = 0.5}):Play()
				Button:SetAttribute("Equipped", false)
				Button.Aesthetics.Enabled = true
			end
		end
	elseif script.Parent:GetAttribute("Equipped") == true then
		game.TweenService:Create(script.Parent, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
		game.TweenService:Create(script.Parent.Outline, TweenInfo.new(0.1), {Transparency = 0.5}):Play()
		script.Parent:SetAttribute("Equipped", false)
		script.Parent.Aesthetics.Enabled = true
	end
end)

Hello @TheRealBloxikGames,

The only issue I see with the snippet of source code you have provided is a logic error.
When the if statement if script.Parent:GetAttribute("Equipped") == false is true, you correctly set the current button as equipped by using script.Parent:SetAttribute("Equipped", true).
However right after that, you have a for loop of which iterates through all of your buttons, including the current button , where you are setting its state back to false. This is where your logic error lies.

An easy fix can be to check that the button from iteration is not the current button.
As provided below.

script.Parent.MouseButton1Up:Connect(function()
	if script.Parent:GetAttribute("Equipped") == false then
		script.Parent.Aesthetics.Enabled = false
		game.TweenService:Create(script.Parent, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 87, 0, 87)}):Play()
		game.TweenService:Create(script.Parent.Outline, TweenInfo.new(0.1), {Transparency = 0}):Play()
		script.Parent:SetAttribute("Equipped", true)

		for _, Button in ipairs(script.Parent.Parent:GetChildren()) do
			if Button:IsA("ImageButton") and Button ~= script.Parent then -- Added a check to make sure the `Button` is not the current button.
				game.TweenService:Create(Button, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
				game.TweenService:Create(Button.Outline, TweenInfo.new(0.1), {Transparency = 0.5}):Play()
				Button:SetAttribute("Equipped", false)
				Button.Aesthetics.Enabled = true
			end
		end
	elseif script.Parent:GetAttribute("Equipped") == true then
		game.TweenService:Create(script.Parent, TweenInfo.new(0.1, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
		game.TweenService:Create(script.Parent.Outline, TweenInfo.new(0.1), {Transparency = 0.5}):Play()
		script.Parent:SetAttribute("Equipped", false)
		script.Parent.Aesthetics.Enabled = true
	end
end)


I hope this resolves your issue. If it doesn’t, I would recommend using the in-built debugging features that Roblox Studio offers.

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