Script Is Running But Nothing Happens and No Errors

Read the title.

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

				for _, Buttons in ipairs(script.Parent:GetChildren()) do
					if Buttons:IsA("ImageButton") then
						game.TweenService:Create(Buttons, TweenInfo.new(0.5, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
						Buttons.Outline.Transparency = 0.5
						Buttons:SetAttribute("Equipped", false)
					end
				end
			else
				game.TweenService:Create(Button, TweenInfo.new(0.5, Enum.EasingStyle.Elastic), {Size = UDim2.new(0, 80, 0, 80)}):Play()
				Button.Outline.Transparency = 0.5
				Button:SetAttribute("Equipped", false)
			end
		end)
	end
end

Try prints before each if check to see what the variable is beforehand. If the Output print isn’t what you expect to see then look at the section of code that sets that variable.

For example:

for _, Button in ipairs(script.Parent:GetChildren()) do
    print("Button's name = ", Button.Name)
	if Button:IsA("ImageButton") then
		Button.MouseButton1Up:Connect(function()
            print("Equipped = ", Button:GetAttribute("Equipped"))
			if Button:GetAttribute("Equipped") == false then
        -- etc.
1 Like

Could you confirm that the script is a LocalScript or a Script running on RunContext = "Client"?

Server Scripts do not work in a client-based instance.

It’s a LocalScript, although I’ve tried it with a Script on RunContext Client and that had similar bad results.

Printing it at after the “for _,” prints each button’s name twice, and printing it “if GetAttribute == Value” print’s the button’s name that’s being pressed. When testing I was looking at the atttribute inside the buttons themselves in the my player’s playergui and nothing happened.

I found the issue. The script is printing that the “Equipped” attribute is true, when it the workspace it shows as false. I’ve tried it as both a LocalScript and Script on Client and nothing seems to work.

I put a print statement after the :SetAttribute() and the script seems to think it actually changed the attribute when in reality it didn’t.

What can I do to fix it?

When the client changes something, it won’t appear on the server. You have to connect a RemoteEvent or (recommended) UnreliableRemoteEvent and fire that to change the attribute.

I’m checking the attribute in my playergui on client side, not server side, therefore it should change.

And the rest of the script should still run even though the attribute isn’t changing, since there are no errors, but the rest of the script doesn’t run…

Solved it with the help of another post.

Please link that post so others can find out how it fixed your issue.

1 Like

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