Button not working when copying it and parenting it to the original at the same position

Hello i have text buttons inside of a UIGridLayout and i want it to grow when hovering over it. So to achieve this i clone the button then parent it to itself because i can’t change the size of a button parented to a UIGridLayout but the problem is the original button doesn’t get activated when you click on it

Here’s the code :

for i, weaponShopButton: TextButton in pairs(CollectionService:GetTagged("WeaponShopButton")) do
	local placeholderButton = nil
	local shrinkTween: Tween = nil
	local growTween: Tween = nil
	
	weaponShopButton.MouseEnter:Connect(function()
		if shrinkTween then
			shrinkTween:Cancel()
			shrinkTween = nil
		else
			placeholderButton = weaponShopButton:Clone()
			placeholderButton.Parent = weaponShopButton
		end
		
		placeholderButton.Size = UDim2.new(1,0,1,0)
		
		local uiGradient: UIGradient = placeholderButton:WaitForChild("UIGradient")
		
		uiGradient.Offset = Vector2.new(-1, 0)
		
		growTween = TweenService:Create(placeholderButton,TweenInfo.new(0.3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Size = UDim2.new(1.2,0,1.2,0)})
		growTween:Play()

		local slideEffect = TweenService:Create(uiGradient,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Offset = Vector2.new(5,0)})
		slideEffect:Play()
	end)
	
	weaponShopButton.MouseLeave:Connect(function()
		if growTween then
			growTween:Cancel()
		end
		
		shrinkTween = TweenService:Create(placeholderButton,TweenInfo.new(0.3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Size = UDim2.new(1,0,1,0)})
		shrinkTween:Play()
		
		shrinkTween.Completed:Connect(function(playbackState)
			if playbackState == Enum.PlaybackState.Cancelled then return end
			
			placeholderButton:Destroy()
			shrinkTween = nil
		end)
	end)
	
	weaponShopButton.Activated:Connect(function()
		print("Activated") -- Does not print
		
		--Random stuff
	end)
end

Yay i found a solution instead of cloning it and do all of this crazy stuff i just added a UIScale inside of the button and tweened the scale property to change the size of my buttons while it’s parented to the UIGridLayout
Here’s the new code :

for i, weaponShopButton: TextButton in pairs(CollectionService:GetTagged("WeaponShopButton")) do
	local shrinkTween: Tween = nil
	local growTween: Tween = nil
	
	weaponShopButton.MouseEnter:Connect(function()
		local uiGradient: UIGradient = weaponShopButton:WaitForChild("UIGradient")
		uiGradient.Offset = Vector2.new(-1, 0)
		
		local uiScale: UIScale = weaponShopButton:WaitForChild("UIScale") 
		
		growTween = TweenService:Create(uiScale,TweenInfo.new(0.3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Scale = 1.2})
		growTween:Play()

		local slideEffect = TweenService:Create(uiGradient,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Offset = Vector2.new(5,0)})
		slideEffect:Play()
	end)
	
	weaponShopButton.MouseLeave:Connect(function()
		if growTween then
			growTween:Cancel()
		end
		
		local uiScale: UIScale = weaponShopButton:WaitForChild("UIScale")
		
		shrinkTween = TweenService:Create(uiScale,TweenInfo.new(0.3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Scale = 1})
		shrinkTween:Play()
	end)
	
	weaponShopButton.Activated:Connect(function()
		print("Activated") -- It prints now !
		
		--Random stuff
	end)
end

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