OnClick not activating when clicking TextButton

I’m trying to make a local script for my shop which allows the player to switch between shop tabs. However the script is not activating when I click on the button however other functions of the script do work.

Here's the script being used (inside of the button)
local Shop = script.Parent.Parent.Parent.Shop.Shop

local toopen = Shop[script.Parent.Name]

-- THIS BIT DOES NOT ACTIVATE WHEN I CLICK THE BUTTON (BREAKPOINT DOESN'T FIRE)
script.Parent.MouseButton1Click:Connect(function()
	for _, v in (Shop:GetChildren()) do
		if v.Name ~= toopen then
			v.Visible = false
		end
	end
	
	toopen.Visible = true
	
	local Click = Instance.new ("Sound")
	Click.Parent = script
	Click.SoundId = 4499400560
	Click:Play()
	wait(1)
	Click:Destroy()
end)

-- ***EVERYTHING BEYOND THIS POINT FUNCTIONS AS NORMAL (SOMEHOW)

local button = script.Parent
local originalSize = button.Size

local originalPosition = button.Position

local scaleFactor = 1.05

local function onMouseEnter()
	button.Size = UDim2.new(originalSize.X.Scale * scaleFactor, originalSize.X.Offset * scaleFactor, originalSize.Y.Scale * scaleFactor, originalSize.Y.Offset * scaleFactor)
end

local function onMouseLeave()
	button.Size = UDim2.new(originalSize.X.Scale, 0, originalSize.Y.Scale, 0)
end

button.MouseEnter:Connect(onMouseEnter)
button.MouseLeave:Connect(onMouseLeave)

.

And here's the hierarchy in the explorer

image

(Both change buttons function exactly the same)

The output is left completely empty as well by the way.

Why is this script not firing when I click on the button and what can I do to fix that?

Thanks in advance!

3 Likes

I think its because youre only calling 3 parents when you should be calling 4

local Shop = script.Parent.Parent.Parent.Parent.Shop.Shop

If its not, are you getting any errors from the script?

2 Likes

After copying that in, I get this array of errors:

By the way little update: to reduce confusion, I changed the names of the shops to these:

image

Resulting in the script(s) looking like this:
local Shop = script.Parent.Parent.Parent.Shop2.Shop3

local toopen = Shop[script.Parent.Name]

script.Parent.MouseButton1Click:Connect(function()
	for _, v in (Shop:GetChildren()) do
		if v.Name ~= toopen then
			v.Visible = false
		end
	end
	
	toopen.Visible = true
	
	local Click = Instance.new ("Sound")
	Click.Parent = script
	Click.SoundId = 4499400560
	Click:Play()
	wait(1)
	Click:Destroy()
end)

local button = script.Parent
local originalSize = button.Size

local originalPosition = button.Position

local scaleFactor = 1.05

local function onMouseEnter()
	button.Size = UDim2.new(originalSize.X.Scale * scaleFactor, originalSize.X.Offset * scaleFactor, originalSize.Y.Scale * scaleFactor, originalSize.Y.Offset * scaleFactor)
end

local function onMouseLeave()
	button.Size = UDim2.new(originalSize.X.Scale, 0, originalSize.Y.Scale, 0)
end

button.MouseEnter:Connect(onMouseEnter)
button.MouseLeave:Connect(onMouseLeave)
1 Like

The LocalScript is inside 4 Parents
Buttons > Donate > Tabs > Shop

1 Like

Maybe try waiting for them?

Shop:WaitForChild("Donate")
2 Likes

I changed that for all of them and the code doesn’t complain however the MouseButton1Click function still does not fire. Still no errors given

Here’s a link to a model of the GUI

1 Like

may I see the updated error with the new names?

1 Like

No errors are outputted when I run the script

are you sure it isn’t working? looks to me like it’s working properly. you may not see the change because all 3 of the shop tabs are clones of each other.

2 Likes

same for me, it works but it seems like its not since all of them are the same.

2 Likes

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