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
(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?
By the way little update: to reduce confusion, I changed the names of the shops to these:
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)
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.